+ 1
What is wrong in this code (trying to print min/max number from array element)
#include <iostream> using namespace std; int main() { int n,arr[n],max,min; cin>>n; cout<<"Array: "; for(int i=0;i<n;i++){ cin>>arr[i]; } max=arr[0]; for(int i=0;i<n;i++){ if(max<arr[i]){ max=arr[i]; } } min=arr[0]; for(int i=0;i<n;i++){ if(min>arr[i]){ min=arr[i]; } } cout<<"Max: "<<max<<endl; cout<<"Min: "<<min<<endl; return 0; }
4 Answers