Why is show negative output when i calculate 50!

#include
using namespace std;
long long fact(int n)
{
if(n==0)
{
return 1;
}
else
{
return n*fact(n-1);
}
}

int main() {
// your code goes
int t;
cin>>t;
while(t–)
{
int n;
long long z;
cin>>n;
z=fact(n);
cout<<z<<endl;
}

return 0;

}

Because 50! is too large to fit in long long int

1 Like