+ 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; }

30th Mar 2022, 2:59 PM
Bone(Geremsa)
Bone(Geremsa) - avatar
4 Answers
+ 2
Bone declare array after taking input n as: cin>>n; int arr[n]; edit: only this correction is needed.
30th Mar 2022, 3:12 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
Ok
30th Mar 2022, 3:15 PM
Bone(Geremsa)
Bone(Geremsa) - avatar
+ 1
Jayakrishna yes i noticed it thnks for figuring out error
30th Mar 2022, 3:17 PM
Bone(Geremsa)
Bone(Geremsa) - avatar
0
Bone You're welcome.. see edit above..
30th Mar 2022, 3:42 PM
Jayakrishna šŸ‡®šŸ‡³