0

Why CPP program not give factorial number after 32 ???

17th Aug 2017, 4:50 PM
Damodar Joshi
Damodar Joshi - avatar
5 Respuestas
+ 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...
21st Aug 2017, 10:43 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
Can you share your code? It must be due to a value exceeding the maximal value of your type
17th Aug 2017, 5:05 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
use long while variable declaration
17th Aug 2017, 5:47 PM
Million Gashawbeza
Million Gashawbeza - avatar
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; }
18th Aug 2017, 1:38 AM
Damodar Joshi
Damodar Joshi - avatar
0
see this is code this gives minus value of 32
18th Aug 2017, 1:38 AM
Damodar Joshi
Damodar Joshi - avatar