SHARE
TWEET

C++ Factorial Finder Recursive Function

a guest Aug 30th, 2016 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top