ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

A number's digit sum is computed by the procedure below for N = 98765. What is printed?

A number's digit sum is computed by the procedure below for N = 98765. What is printed?
s = 0; m = N
while m > 0
    s = s + (m mod 10)
    m = m div 10
end while
Print s
  1. A. 5
  2. B. 15120
  3. C. 56789
  4. D. 35

Correct answer: D. 35

Adding the digits 9 + 8 + 7 + 6 + 5 gives 35. The digit count is 5, the product of the digits is 15120, and the reverse of the number is 56789.

More Pseudocode and Code Tracing questions

Exams that ask this topic