Small Factorial! Wrong Answer!

I have wrote the following code, it works perfectly in my compiler but gives wrong answer on my submission;

#include <iostream>

using namespace std;
int my_func(int n)
    int fact;
    else if(n>1)
      return fact;
int main()
    int i;
    cin >>i;
    for(int x=0;x<i;x++)
        int n;
        cin >>n;
    return 0;

Could anyone help me out!

100 factorial cannot be stored in any primitive data type in C and C++ . Check the constraints on n

In general, Its a humble request that please do check the problem you are facing on discussion forum search box…!

Whole discussion is present up here in this link:

As @acodebreaker2 100 factorial do not fits in any integer datatype since length of 100 factorial is of 158 numbers.

Go through with the above link you’ll get the detailed explanation up there… :slight_smile:

EDIT: And do check this link of how to compute large factorials in c or c++

As you are using C++ you don’t have any default mechanisms to store large numbers as large as 100!(158 digits).
You can try using arrays by storing each digit of the number in a different index and modify the printing accordingly. Try to solve the problem using this approach :slight_smile: If you still don’t get it you can always look other’s solution

Could you help me out to solve the problem recursively ?