ProgrammingHardTCS NQT · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer i = 1, c = 0
while (i <= 100)
    i = i * 2 + c
    c = c + 1
end while
Print c, i
  1. A. 6 118
  2. B. 7 120
  3. C. 6 121
  4. D. 6 57

Correct answer: C. 6 121

The new i uses the old c: 1 → 2 → 5 → 12 → 27 → 58 → 121, with c going up by one each pass. 121 is the first value over 100, after 6 passes: 6 121.

More Pseudocode and Code Tracing questions

Exams that ask this topic