If I have an array, e.g.
10, 4, 7, 8
The value of the maximum element is
10
How can I find this value?
Here’s my attempt:
int highNum = 0;
int m;
int list[4] = {10, 4, 7, 8};
for (m = 0 ; m < size ; m++);
{
if (list[m] > highNum)
highNum = list[m];
cout << list[m];
}
cout << highNum;
I am trying to write a simple loop to store a max value from an array, and I wrote this thinking it would work, but for some reason at the beginning of the for loop it stores the m variable as 4 and exits the loop.
You have a semicolon after your
forstatement:This should be: