Saturday, January 21, 2012

Number Of Trailing Zero's in N!

#include<stdio.h>


long zero(long number,long factor)
{
long total,deno;


if(number == 5) return 1;
total=0; deno = factor;


while(deno < number)
{
total += number/deno;
deno *= factor;
}
return total;
}


int main()
{
long N,c2,c1;
while(scanf("%ld",&N)==1)
{
c1 = zero(N,2);  c2 = zero(N,5);
if(c1<c2) printf("%ld\n",c1);
else      printf("%ld\n",c2);
}
return 0;
}
/*
Input:
15 24  100
Output:
3 4 24
*/

No comments:

Post a Comment