Given an integer n, write a function that returns count of trailing zeroes in n!.
Read full article from Count trailing zeroes in factorial of a number | GeeksforGeeks
Trailing 0s in n! = Count of 5s in prime factors of n! = floor(n/5) + floor(n/25) + floor(n/125) + ....
int
findTrailingZeros(
int
n)
{
// Initialize result
int
count = 0;
// Keep dividing n by powers of 5 and update count
for
(
int
i=5; n/i>=1; i *= 5)
count += n/i;
return
count;
}
No comments:
Post a Comment