# Factorial problem(Easy)

The following program works for small numbers such 5, 10, 11 etc but as soon as i enter a large number such as 60, the no of trailing zeroes in its factorial shows zero. Can anyone help?

``````#include<iostream.h>
``````

#include<math.h>
#include<conio.h>
unsigned long int factorial(unsigned long int);

int main()
{
unsigned long int t,n;
unsigned int count,i;
cin>>t;
unsigned long int a[10];
for(i=0;i<t;++i)
{
cin>>n;
a[i]=factorial(n);
}
for(i=0;i<t;++i)
{
count=0;
while(a[i]>0)
{
if(a[i]%10==0)
count++;
a[i]=a[i]/10;
}
cout<<count<<’\n’;
}
getch();
return(0);
}

unsigned long int factorial(unsigned long int x)
{
unsigned int i=1;
unsigned long int f=1;
while(i<=x)
{
f=f*i;
i++;
}
return(f);
}

60! is becomming too large for it to thats why it is unable to process
instead try to find the cases in which 10 can be possible in the factorial

look below-

int count =0;
if (n==5)
{
return 1;
}

``````    for(int j=5;n/j >=1;j=j*5)
{
count+=n/j;
}
return  count;
``````

pls ask again if you don’t understand

@recrsnsettler 60! is very very large number and it cannot be accomodated in unsigned long int that’s why you are getting this error.