ProgrammingModerateTCS NQT · Infosys · 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 <= 20)
    i = i * 2
    c = c + 1
end while
Print i, c
  1. A. 16 4
  2. B. 32 6
  3. C. 20 5
  4. D. 32 5

Correct answer: D. 32 5

i runs 1, 2, 4, 8, 16 (each below 21) and then becomes 32 after the fifth pass, so i = 32, c = 5.

More Pseudocode and Code Tracing questions

Exams that ask this topic