ProgrammingEasyInfosys · Capgemini pattern

What will be the output of the following pseudocode? (/ is integer division.)

What will be the output of the following pseudocode? (/ is integer division.)
Integer n = 2405, c = 0, s = 0
while (n > 0)
    s = s + n mod 10
    c = c + 1
    n = n / 10
end while
Print c, s
  1. A. 3 11
  2. B. 4 9
  3. C. 4 11
  4. D. 4 5042

Correct answer: C. 4 11

Each pass peels off the last digit: 5, 0, 4, 2 → c = 4 digits (the 0 still counts as a digit) and s = 5 + 0 + 4 + 2 = 11. '3' skips the zero digit; 5042 is the reversed number, which this code never builds.

More Pseudocode and Code Tracing questions

Exams that ask this topic