Max_value_return in an array
also help me out how to understand the constraits mention in the problem so i can optimize my solution while solving the problems
Hey Vikaspal !
your size of array is 5 i.e maximum index can be accessed is arr[4],but in function max_value(){ when i=4; your if condition is accessing arr[5] } which is a garbage value,(bounds error).so try the following code
int largest_element = arr[0];
for(int i=1;i<n;i++)
{
largest_element = max( largest_element,arr[i]);
}
return largest_element;