Advertisement
kokokozhina

v3_3

Dec 15th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream> //exercise 4
  2. #include <algorithm>//create a recursive function that computes n-Fibonacci number
  3.  
  4. using namespace std;
  5.  
  6. int fib(int n)
  7. {
  8.     if (n < 2)
  9.         return n;
  10.     else
  11.         return fib(n - 1) + fib(n - 2);
  12. }
  13.  
  14. int main()
  15. {
  16.     int n;
  17.     cout << "Which Fibonacci number do you want to know? ";
  18.     cin >> n;
  19.     cout << "Your Fibonacci number is " << fib(n) << endl;
  20.     system("pause");
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement