codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
/* Calculate the factorial of 171 used in blog http://www.jiangtanghu.com/blog/2011/01/22/big-numbers/ */ #include <iostream> using namespace std; double factRecursive(double num); double factNonRecursive(double num); int main() { cout<<endl; cout<<"Recursive: the factorial of 170 is "<<factRecursive(170)<<endl; cout<<"Recursive: the factorial of 171 is "<<factRecursive(171)<<endl; cout<<endl; cout<<"NonRecursive: the factorial of 170 is "<<factNonRecursive(170)<<endl; cout<<"NonRecursive: the factorial of 171 is "<<factNonRecursive(171)<<endl; cout<<endl; return 0; } double factRecursive (double num) { if (num==0) return 1; else return num*factRecursive(num-1); } double factNonRecursive (double num) { double fact=1; for (double i=2;i<=num;i++) fact *=i; return fact; }
Private
[
?
]
Run code
Submit