ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains

The number of trailing zeros in the decimal form of 2^20 5^3 is found by the procedure below, which divides out factors of 10 one at a time while the number ends in 0. What is printed?

The number of trailing zeros in the decimal form of 2^20 * 5^3 is found by the procedure below, which divides out factors of 10 one at a time while the number ends in 0. What is printed?
n = 2^20 * 5^3; count = 0
while n mod 10 == 0
    n = n div 10; count = count + 1
end while
Print count
  1. A. 3
  2. B. 20
  3. C. 4
  4. D. 6

Correct answer: A. 3

2^20 * 5^3 = 2^17 * 10^3, so exactly 3 factors of 10 divide it. Counting factors of 2 gives 20, counting factors of 5 and adding one gives 4, and doubling the 10-count gives 6.

More Pseudocode and Code Tracing questions

Exams that ask this topic