I am running my code in IDE and its working correctly, but chef isn't accepting my answer. I have used recursive approach

Link to problem: FCTRL2 Problem - CodeChef

#include <stdio.h>

long int fact(int n)
{
if (n==0)
{
return 1;
}
else
return n * fact(n-1);
}

int main(void) {
//Calculate Factorial
int i, t;
long int res;
scanf(“%d”, &t);
while(t–)
{
scanf(“%d”, &i);
res = fact(i);
printf(“%d\n”, res);
}
return 0;
}

Try this:

Input

100

Output

A fairly large number with about 24 zeroes at the back

What do we learn?

long int can’t store 100 factorial. You need to use something like string and do string multiplication.

1 Like