Advertisement
Guest User

fibonacci

a guest
Oct 19th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fibo(int n)
  5. {
  6.     if(n <= 1)
  7.        return 1;
  8.    else
  9.    {
  10.        return fibo(n-1) + fibo(n-2);
  11.    }
  12. }
  13.  
  14. int main()
  15. {
  16.    int n;
  17.    cin >> n;
  18.  
  19.     cout << "Fibonacci(" << n << ") = " << fibo(n) << endl;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement