Guest User

C++ Factorial Finder Recursive Function

a guest
Aug 30th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double f(double x)
  6. {
  7.     if(x == 1) // base case
  8.     {
  9.         return 1;
  10.     }
  11.     else
  12.     {
  13.         return x * f(x-1); // recursion case
  14.     }
  15. }
  16.  
  17. int main()
  18. {
  19.     // Test:
  20.     cout << f(170); // the biggest number for C++ to calculate the factorial of
  21. }
Add Comment
Please, Sign In to add comment