ProgrammingModerateWipro · Accenture 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 = 25, z = 0
while (n > 0)
    n = n / 5
    z = z + n
end while
Print z
  1. A. 5
  2. B. 7
  3. C. 25
  4. D. 6

Correct answer: D. 6

This counts the trailing zeros of 25!: 25/5 = 5 multiples of 5, then 5/5 = 1 multiple of 25 (contributing an extra 5), then 0. 5 + 1 = 6. Counting only the multiples of 5 gives 5.

More Pseudocode and Code Tracing questions

Exams that ask this topic