Testcases failed

#include
using namespace std;

void maxvalue(int a[], unsigned int n){
int maxvalue=0;
int temp;
for(int i=0;i<n;i++){
temp =a[i];
if(temp>maxvalue){
maxvalue=temp;
}
}
cout<<maxvalue;
}

int main(){
unsigned int n;
cin>>n;

int a[500]={0};
for(int i=0; i<n;i++){
	cin>>a[i];
}

maxvalue(a,n);
return 0;	

}

hello @thakur0_0
consider a case where all elements of ur array is negative,in that case u will print 0 which is wrong.

to rectify it initialise ur max with any value in array.

with any value wouldnt work for many cases i guess, INT_MIN would work for every case i believe?

if u intialise with a value that in present in array then it will work.

hey understood , actually u tried to say that i initialise my maxnum =a[i]; (right)?

yeah right . . . . .

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.