Saturday, 3 November 2012

Total number of Trailing zeros in the factorial of an integer


#include<stdio.h>
int main()

{

long int i,n;
int zero,j;
clrscr();
        printf("Enter the number:");
scanf("%ld",&n);
     zero=0;
for(j=5;j<n;j*=5)
{
zero+=n/j;
}
printf("\n%d",zero);

getch();

return 0;
}


Output:
Eneter the number : 25

5

1 comment:

  1. Nice code and post! There's a good explanation of the algorithm on this page too:

    Trailing zeros factorial

    ReplyDelete