Java: Compute the number of trailing zeros in a factorial
Trailing Zeros in Factorial
Write a Java program to compute the number of trailing zeros in a factorial.
Example
7! = 5040, therefore the output should be 1.
Pictorial Presentation:
Sample Solution:
Java Code:
Sample Output:
Input a number : 5040 Number of trailing zeros of the factorial 5040 is 1258
Flowchart:
For more Practice: Solve these Related Problems:
- Modify the program to return the number of trailing ones instead.
- Write a program to find the highest power of 2 in the factorial.
- Modify the program to return the count of factors of 5 in the factorial.
- Write a program to compute the factorial without storing large numbers.
Go to:
PREV : Add Without Operators.
NEXT : Merge Two Sorted Arrays.
Java Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.