Why 1 test case is wrong?

i have written this code.,1 test case is wrong

#include
using namespace std;

int main(){
int arr[10], max=0;
int i=0,n;
cin>>n;
for(i=0;i<n;i++){
cin>>arr[i];
}
for(i=0;i<n;i++)
{
if(arr[i]>max){
max=arr[i];
}
}
cout<<max;
return 0;
}

Hello @RASHMI2000,

There are two things you have to correct in your code:

  1. Range of Numbers can be between -1000000000 to 1000000000
    Which means, the array can have negative numbers also.
    Your code will print 0 if all the elements of array are negative.
    Solution:
    Initialize max=INT_MIN; // the minimum value of int.

  2. How are you so sure that there would be only 10 elements in the array.
    arr[10]
    Solution:
    cin>>n;
    int arr[n];

Hope, this would help.
Give a like, if you are satisfied.

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.