Alternative Factorial Solution

This solution was submitted by James Rouzier. The code takes advantage of the fact that the number of times a particular power of 5 shows up is also used to compute the number of times the next power of 5 appears--all you need to do is divide by 5 again.

#include <stdio.h>

int findzeros(unsigned int n);

int main(int argv, char *argc[])
{
    unsigned int i = 0;
    printf("Please enter the factorial: ");
    scanf("%u",&i);
    printf("The amount of zeros in factorial %u! is %u\n",i,findzeros(i));

    for (i = 0;i < 0;i++)
    {
        printf("The amount of zeros in factorial %u! is %u\n",i,findzeros(i));
    }
    return 0;
}

int findzeros(unsigned int n)
{
    int result = 0;
    while ( n > 0)
    {
        n /= 5;
        result += n;
    }
    return result;
}
Get the code