REGARDING SMALL FACTORIALS PROBLEM IN BEGINNER SECTION

WHAT IS WRONG IN MY CODE THE ONLINE COMPILER IS SAYING WRONG ANSWER

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

Given, n <= 100; now, 100! cannot be contained in ‘int’ or ‘long long’ variable. I am afraid, you need to program to multiply two numbers (stored as a ‘string’ or ‘char’ array) manually to solve the problem (or you can try with a different language, with ‘Big Integer’ library functions).

1 Like

Don’t Understand plzz elaborate

Data type ‘int’ can store 32 bits, while ‘long’ can store 64 bits. Factorial of 100 is so large that it can’t be stored even in long variable. The only way to store a large element is by array representation, ie, each digit occupies an array index.

Eg: 75337 can be represented as arr[] = {7, 5, 3, 3, 7}.

THANKS BRO