Factorial code not accepted by codechef

submission link:
https://www.codechef.com/viewsolution/19060351

Please give your submission link here instead of code, and modify title and description of question to something meaningful

Your Code is almost correct just one mistake is there that is you have not putted blocks { } in Last for loop and also remove " const" in the first line of main()…
So here is your corrected code:-

#include<stdio.h>
int main()
{
int t;
int i,c;
scanf("%d",&t);
int n[t-1],f[t-1];
for(i=0;i<t;i++)
{
scanf("%d",&n[i]);
f[i]=1;
for(c=1;c<=n[i];c++)
f[i]*=c;
}
for(i=0;i<t;i++)
{printf("%d\n",f[i]);
}
return 0;}

Just look at constraints. Especially this one 1 <= n <= 100

Just imagine 10^2 \times (9.9)10 \times (9.8)10 \times (9.7)10 \times (9.6)10 \times (9.5)10 \times (9.4)10 ....

This makes something even greater than 10^{100} but do you remember the range of an integer (even taking 64 bit unsigned one) is 2^{64} -1 that is roughly nearly equal to 10^{19}(upper bound not lower)

So your integer overflows, and tada its a wrong answer.

Give this a read.
http://www.cplusplus.com/articles/DE18T05o/

I would suggest you to first search these stuffs on google,see through others code,check where your code mismatches,see if anyone else had the same problem,if u still cant get it done,then ask it on the discuss,as i think these question’s solutions and common errors are easily available on google.

1 Like

Thnks everyone

//