Need help with understanding/calculating Output in an Array

The answer is "9" for this problem, but I can't figure out how to reach this conclusion. Could someone please explain to me (step-by-step) how I can calculate the correct output?

Here's the problem:

 ``1234567891011`` `````` int arr[5] = {2, 6, 5, 7, 9}; int la = arr[0]; for (int c = 1; c < 5; c = c + 1) { if (arr[c] > la) { la = arr[c]; } } cout << la << endl;``````

THANKS!
Last edited on
if 9 is the answer, what is the question ?
I expect the explanations provided for an earlier question should guide you as to the sort of thought-processes which are required.

http://www.cplusplus.com/forum/beginner/87337/

Basically, take a sheet of paper.
Write down on a separate line the names of the variables:

`la`

`c`

` arr[c]`

Next to the variable name, write down its current value.
Then work your way line-by-line through the for loop. Make a note of the new value of each variable as you step through the code.
Last edited on
Topic archived. No new replies allowed.