ProgrammingModerateLTIMindtree · Cognizant GenC

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer n = 4021, r = 0
while (n > 0)
    r = r * 10 + (n mod 10)
    n = n / 10
end while
Print r
  1. A. 4021
  2. B. 1204
  3. C. 1240
  4. D. 124

Correct answer: B. 1204

The digits are peeled off from the right: r = 1, 12, 120, 1204.

More Pseudocode and Code Tracing questions

Exams that ask this topic