#include
using namespace std;
int main() {
int N,max=0;
int a[N];
cin>>N;
for(int i=0;i<N;i++){
cin>>a[i];
cout<<endl;
}
for(int i=0;i<N;i++){
if(max<a[i]){
max=a[i];
}
}
cout<<max;
return 0;
}
Could you please tell me what I'm doing wrong?
@vinayakhajuria Range of Numbers can be between -1000000000 to 1000000000.so when all numbers are negative your code will give answer as 0 since max=0 will never get updated but correct answer should be the less negative value.
so initialize your max from INT_MIN so that it will always less than any range number
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.