whats wrong with this code??

hii
in my computer am gettin crct o/p for the small factorial problem. if i run this in codechef, 1 st time i got runtime error. then i added return 0. again i uploaded and got it as wrong answer. can anyone help me to solve this??? this would be a great help. plz, ppl who knws guide me.

#include<stdio.h>
int main()
{
    int test,i,j,fact;
    printf("\n enter the no. of test cases");
    scanf("%d",&test);
    int a[100];
    for(i=0;i<test;i++)
    {
          scanf("%d",&a[i]);
                       }
                       for(i=0;i<test;i++)
                       {
                                          fact=1;
                                          for(j=1;j<=a[i];j++)
                                          {
                                                              fact=fact*j;
                                                              }
                                                              printf("%d",fact);
                                                              printf("\n");
                                                              }
                                                              return(0);
`                                                              `}

Your code is wrong because in this problem n can be uptil 100 . n! will get out of range of 32 bit and 64 bit integers for small values of n itself . For this problem you have to use some BigInteger library . Try running your code with values of n like 50 ,51 ,52 , you will see answers given by your code which is not factorials of these numbers but some junk values .

Hello,

The limit test case for this problem can be as large as 100…

This means you need to compute 100!, correct?

Well, it turns out that 100! has over 600 decimal digits and it’s not possible to represent it using any standard C data type.

This means you need to write your own code snippet that manipulates large integers… This is a somewhat classic question on programming contests and there are many ways of representing large numbers. One of the most common and simple to implement involves maintaining the digits of the number in an array, with the least significant digit on the 0-indexed position of the array.

To read a complete tutorial on this subject, you can refer to the tutorial of this problem, which you can find here.

Good luck,

Bruno

//