Small Factorial

what is wrong is this code, codechef is showing wrong answer?

#include<iostream>

using namespace std;

int fact (int x){

if(x &lt;=1){

return 1;

    }

return x*fact(x-1);

}

int main(){

int t;

    cin>>t;

int arr[t];

for(int i = 0<t;i++){

int x;

        cin>> x;

        arr[i]=fact(x) ;

    }

for(int i = 0; i <t; i++)

    {

       cout<<arr[i]<<endl;

    }

}`

Hi @hardy_971.

N can be 100 in worst case. 100 factorial is a huge number, and won’t fit in int type.

You can refer to Find the Factorial of a large number - GeeksforGeeks to understand how to solve the question.

Hope this helped :slight_smile:

1 Like