#include <stdio.h>
long fact(int);
long fact(int nu)
{
int i,x;
x=1;
for(i=1;i<=nu;i++)
x*=i;
return x;
}
int main(void)
{
int t,n;
scanf("%d",&t);
while(t!=0)
{scanf("%d",&n);
printf("%ld\n",fact(n));
t–;
}
// your code goes here
return 0;
}
So,you are getting wrong answer for this problem because factorial above 20 can’t be accommodated in the predefined data types.100! has approx. 150+ digits.Try to think and find a way to store each digit in an array.If you are not able to get that still,don’t worry chef’s have a solution for that too!
Here’s the tutorial for this problem:-
Tutorial
Hope this helps.
Happy Coding!!