Encountered an issue with the Small factorial program

I am facing an issue with this program of small factorial even though my code is right but still, it is not accepting my code. Does anyone know what is the problem with my code? :sweat_smile:

Here is the code:

#include<stdio.h>

int main()
{
    int num;
    scanf("%d", &num);
    for(int i = 0; i < num; i++)
    {   int a,fact = 1;
        scanf("%d", &a);
        while( a > 0)
        {   
            fact *= a;
            a--;
        }
        printf("%d\n",fact);
    }
    return 0;
}

Input
An integer t, 1<=t<=100, denoting the number of test cases, followed by t lines, each containing a single integer n, 1<=n<=100.

As you can see, n can go up to 100.
And 100! is this big.

93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

The maximum value you can fit in an Integer is 2147483647.
This link provides you with information about limits in C and CPP.

You might want to use arrays, or big integers (available in specific languages) to solve this problem.

3 Likes

So, is this program only possible with arrays if we want put limit on integers ?
Thanks, geek :innocent: