0
Why CPP program not give factorial number after 32 ???
5 Answers
+ 4
@Damodar Joshi
In C++, the highest number you can represent by built in types is (2^64)-1, a 12 digit number.
33! has 37 digits...
Thus exceeding the limit forces the number to become its one's or two's complement, which is used to represent negative numbers...
+ 3
Can you share your code?
It must be due to a value exceeding the maximal value of your type
+ 2
use long while variable declaration
0
#include <iostream>
using namespace std;
int main()
{
long fact =1;
long n;
cin>>n;
for(long i=1;i<=n;i++)
{
fact =fact*i;
}
cout<<"Factorial of number is "<<fact;
return 0;
}
0
see this is code this gives minus value of 32