ProgrammingVery hardProduct company OA

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 c = 0
for (n = 1 to 200)
    Integer s = 0, t = n
    while (t > 0)
        s = s + t mod 10
        t = t / 10
    end while
    if (s == 10)
        c = c + 1
    end if
end for
Print c
  1. A. 18
  2. B. 10
  3. C. 20
  4. D. 19

Correct answer: D. 19

Two-digit numbers with digit sum 10: 19, 28, 37, 46, 55, 64, 73, 82, 91 → 9. In 100–199 the last two digits must sum to 9: 109, 118, 127, 136, 145, 154, 163, 172, 181, 190 → 10. 200 has digit sum 2. Total 19. Forgetting 190 (or 109) gives 18.

More Pseudocode and Code Tracing questions

Exams that ask this topic