It is given an integer "p". I have to find a number "n" for which "n factorial" has "p" numbers of zero at the end. Here is the solution i thought, but i am not sure if it is a solution for this problem. Do i have to make a function to calculate the factorial and another function to get the zeros?
Code:
int p;
int count5=0;
int i;
int copy_i;
printf("Enter p: ");
scanf("%d",&p);
for(i=1; ;i++)
{
copy_i=i;
while(copy_i/5)
{
if(copy_i%5==0)
{
count5++;
copy_i=copy_i/5;
}
else
{
break;
}
}
if(count5==p)
{
printf("The minimum number n is: %d.",i);
break;
}
else if(count5>p)
{
printf("No match for n! with %d zero.",p);
break;
}
}
Comment