ProgrammingModerateTCS NQT · Wipro

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)

What will be the output of the following pseudocode? (All variables are integers, so / is integer division)
Integer n = 7086351, s = 0, d
while (n > 0)
    d = n mod 10
    if (d mod 2 == 1)
        s = s + d
    end if
    n = n / 10
end while
Print s
  1. A. 16
  2. B. 30
  3. C. 14
  4. D. 17

Correct answer: A. 16

The loop adds only the odd digits of 7086351: 7 + 3 + 5 + 1 = 16. Adding all digits gives 30.

More Pseudocode and Code Tracing questions

Exams that ask this topic