if i run this code against custom input ,i am getting a correct answer,But while submitting this code i am getting test case is failed please explain what is the error in this code
#include
using namespace std;
main()
{
int n,max=0;
cin>>n;
int a[n];
for(int i=0;i<=n;i++)
{
cin>>a[i];
}
for(int i=0;i<=n;i++)
{ if(max<=a[i])
{
max=a[i];
}
else if(i==n)
{
break;
}
}
cout<<max;
}
Programm errror
@tharun
if all numbers in the array are negative, your code will give answer as 0. Dry run and check it yourself.
So Change max =0 to max=INT_MIN
You have to include another header file for this #include< climits >
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.