#include<stdio.h>
int fact(int);
int main()
{
int t,i=1,a[100],flag;
scanf("%d",&t);
if(t>=1&&t<=100)
{
for(i=0;i<t;i++)
{
scanf("%d",&flag);
a[i]=fact(flag);
}
}
for(i=0;i<t;i++)
{
printf("%d\n",a[i]);
}
return 0;
}
int fact(int f)
{
int temp=1;
while(f!=0)
{
temp=temp*f;
f--;
}
return temp;
}
Your idea is wrong(in c but in python… it’s perfectly fine) . Your algorithm works fine for n<=15. But beyond 15 there will be an integer over flow . Still if you have any doubt try these cases
for n=17,ans=355687428096000;
n=18,ans=6402373705728000;
n=50,ans=30414093201713378043612608166064768844377641568960512000000000000
n=100,ans=9332621544394415268169923885626670049071596826438162146859296389
521759999322991560894146397615651828625369792082722375825118521091686400000
0000000000000000000
The above results are pretty clear that these results can not fit in integer data type
Hint: Approach using arrays.
how to resolve it by using array s?
google it mate… u will get algo with explanation
but if u need hint then it is that " take a array of around 200 digits and use the array to store and display the digits of the factorial "