C plus plus doubt

#include
using namespace std;
int main() {int fact=1,n,t;
std::cin>>t;
for(int j=1;j<=t;j++)
{std::cin>>n;
for(int i=1;i<=n;i++)
fact=fact*i;
std::cout<<fact<<endl;
fact=1;}
return 0;}

I have written this code and getting the correct output but when i submit it it says wrong answer.Please help me.its the 4th problem in beginners (most successful)

Because n can have value up till 100 and 100! is 150+ digits long, you can’t use int or longlong to store this. Use arrays.

Here’s the solution https://www.geeksforgeeks.org/factorial-large-number/

PS: always add problem link and format your code.

1 Like