Search⌘ K
AI Features

Trailing Zeros

Understand how to write a C++ function to count trailing zeros in factorial numbers without calculating the full factorial. Explore why counting factors of five is key, and learn how to handle negative input. This lesson enhances problem-solving skills for factorial-related coding challenges.

Challenge

Write a function called countTrailingZeros (int X) that determines the number of trailing zeros at the end of X! (X factorial), where X is an arbitrary input from the user.

Note: In case of a negative number X, your program should return -1.

Example 1

Input: 12

12! = 479001600

Number of zeros at the end of 12! = 2

Example 2

Input: 5

5! = 120

Number of zeros at the end of 5! = 1 ...