Factorial Zeros
int trailing_zeros(int factorial) {
if (factorial == 0) return -1;
int count = 0;
int temp;
for (int i = 1; i <= factorial; i++) {
temp = i;
while (temp % 5 == 0) {
count++;
temp = temp / 5;
}
}
return count;
}
int main()
{
cout << trailing_zeros(13) << endl;
cout << trailing_zeros(100) << endl;
cout << trailing_zeros(932093) << endl;
}Last updated