#87 · Math · Intermediate · 70 XP · about 10 min
The factorial of n, written n!, is 1 × 2 × 3 × ... × n. Factorials grow very fast: 10! is 3,628,800, which ends in two zeros.
Write trailing_zeros(n) that returns how many zeros n! ends with. By definition 0! is 1, which ends in none.
trailing_zeros(5) # returns 1 (5! = 120) trailing_zeros(10) # returns 2 (10! = 3628800) trailing_zeros(25) # returns 6
Ready?
Accept the challenge to start writing. A small timer counts the time this page is in view.
Output appears here.