ProgrammingEasyCapgemini · Infosys pattern

What will be the output of the following pseudocode? (Arrays are indexed from 0.)

What will be the output of the following pseudocode? (Arrays are indexed from 0.)
Integer arr[4] = {4, 9, 2, 7}
Integer m = arr[0]
for (each i from 1 to 3)
    if (arr[i] > m)
        m = arr[i]
    end if
end for
Print m
  1. A. 9
  2. B. 4
  3. C. 2
  4. D. 7

Correct answer: A. 9

This is a running maximum: m goes 4 → 9 and stays 9 because 2 and 7 are smaller.

More Pseudocode and Code Tracing questions

Exams that ask this topic