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:
1 2 3 4 5 6 7 8 9 10 11
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;
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.