- Related Questions & Answers
- C/C++ Program to Count trailing zeroes in factorial of a number?
- Factorial Trailing Zeroes in C++
- Python Program to Count trailing zeroes in factorial of a number
- Java Program to Count trailing zeroes in factorial of a number
- Preimage Size of Factorial Zeroes Function in C++
- C++ Program to Find Factorial of a Number using Dynamic Programming
- How to remove trailing zeroes in a decimal number in Java?
- Count digits in a factorial in C++
- Program for factorial of a number in C program
- C++ program to Calculate Factorial of a Number Using Recursion
- C++ Program to Find Factorial of a Number using Iteration
- C++ Program to Find Factorial of a Number using Recursion
- C++ program to find first digit in factorial of a number
- Find sum of digits in factorial of a number in C++
- Count factorial numbers in a given range in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Counting the number of trailing zeroes in a factorial number is done by counting the number of 2s and 5s in the factors of the number. Because 2*5 gives 10 which is a trailing 0 in the factorial of a number.

Factorial of 7 = 5040, the number of trailing 0’s is 1.

Based on our logic 7! = 2*3*4*5*6*7, it has 3 2s and 1 5s so the number of trailing 0’s is 1.

#include <iostream> using namespace std; int main() { int n = 45; int count = 0; for (int i = 5; n / i >= 1; i *= 5) count += n / i; cout<<"No of trailing 0s in " << n<< "! is " << count; return 0; }

No of trailing 0s in 24! is 10

Advertisements