ProgrammingModerateTCS NQT · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 20, b = 6, c = 0
while (a > b)
    a = a - 3
    b = b + 2
    c = c + 1
end while
Print a, b, c
  1. A. 14 10 2
  2. B. 8 14 4
  3. C. 12 12 3
  4. D. 11 12 3

Correct answer: D. 11 12 3

The gap a − b shrinks by 5 each pass: 14, 9, 4, −1. After 3 passes a = 11 and b = 12, so a > b fails: 11 12 3.

More Pseudocode and Code Tracing questions

Exams that ask this topic