ProgrammingModerateCapgemini · Infosys pattern

What will be the output of the following pseudocode?

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

Correct answer: B. 3 1

Repeated subtraction is division: 10 → 7 → 4 → 1 takes 3 subtractions, and the test 1 >= 3 fails. So c = 3 (the quotient) and a = 1 (the remainder).

More Pseudocode and Code Tracing questions

Exams that ask this topic