ProgrammingModerateTCS NQT · Infosys · Accenture

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer n = 3140, r = 0
while (n > 0)
    r = r * 10 + n mod 10
    n = n / 10
end while
Print r
  1. A. 413
  2. B. 0413
  3. C. 4130
  4. D. 314

Correct answer: A. 413

Digits are taken from the right: r = 0, 4, 41, 413. The leading zero (from the trailing 0 of 3140) vanishes in an integer.

More Pseudocode and Code Tracing questions

Exams that ask this topic