wrong answer

#include<stdio.h>
//#include
int fac(int);
int main()
{
int i;
scanf("%d",&i);
int n;
int k;
int fact;
for(k=0;k<i;k++)
{
scanf("%d",&n);
fact=fac(n);
printf("%d\n",fact);
}
}
int fac(int x)
{
int f;
if(x==1)
return(1);
else
f=x*fac(x-1);
return(f);
}

this code is giving right answer on my comp

Hello,

You are probably trying to solve problem “Small factorials”. In this problem, you need to be able to calculate 100!, which is approx. 9.33262154 × 10^157. This will not fit in an int. It will also not fit in a ‘long’ or a ‘long long’.

You need to be able to calculate bigger values.

2 Likes