Advertisement
Guest User

câu 1

a guest
Feb 27th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fibonacci(int n) {
  5.     if (n < 0) {
  6.         return -1;
  7.     }
  8.     if (n <= 1) {
  9.         return n;
  10.     }
  11.     else return fibonacci(n - 1) + fibonacci(n - 2);
  12. }
  13. int main ()
  14. {
  15.     int n;
  16.     cin >> n;
  17.     for (int i = 0; i < n; i++) {
  18.         cout << fibonacci(i) << " ";
  19.     }
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement