MeehoweCK

Untitled

Oct 29th, 2020
2,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int fibonacci(int n)
  6. {
  7.     if(n <= 2)
  8.         return 1;
  9.     return fibonacci(n - 1) + fibonacci (n - 2);
  10.    
  11.     // UWAGA: w tym konkretnym przypadku rekurencja nie jest rozwiązaniem efektywnym!
  12. }
  13.  
  14. int main()
  15. {
  16.     int n;
  17.     cin >> n;
  18.  
  19.     for(int i = 1; i <= n; ++i)
  20.         cout << fibonacci(i) << '\t';
  21.     cout << endl;
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment