fork(2) download
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. unsigned long long factorial(int x)
  5. {
  6. if(x < 2)
  7. return 1;
  8.  
  9. return x * factorial(x - 1);
  10. }
  11.  
  12. int main() // overflow
  13. {
  14. int x = 25;
  15. unsigned long long f = factorial(x);
  16. std::cout << x << "! = " << f << std::endl;
  17. std::cout << "Max value for ull: " << std::numeric_limits<unsigned long long>::max();
  18. for(int i = 25 ; i > 0 ; --i) {
  19. f /= i;
  20. std::cout << f << '\n';
  21. }
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
25! = 7034535277573963776
Max value for ull: 18446744073709551615281381411102958551
11724225462623272
509748933157533
23170406052615
1103352669172
55167633458
2903559655
161308869
9488757
593047
39536
2824
217
18
1
0
0
0
0
0
0
0
0
0
0