ProgrammingModerateAccenture · TCS NQT

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a[8] = {3, 1, 4, 1, 5, 9, 2, 6}
Integer best = a[0], c = 1
for (each i from 1 to 7)
    if (a[i] > best)
        best = a[i]
        c = c + 1
    end if
end for
Print c, best
  1. A. 5 9
  2. B. 3 9
  3. C. 4 9
  4. D. 6 9

Correct answer: C. 4 9

c counts the values larger than everything before them (records): 3, 4, 5, 9. So c = 4 and best = 9.

More Pseudocode and Code Tracing questions

Exams that ask this topic