konoha279

Cรขu 1

Feb 20th, 2020
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int fibonacci(int n)
  4. {
  5.     if (n == 1 || n == 2) return 1;
  6.     return fibonacci(n - 1) + fibonacci(n - 2);
  7. }
  8. void DaySoFibonacci(int n)
  9. {
  10.     for (int i = 1; i <= n; i++)
  11.     {  
  12.         cout << fibonacci(i)<<" ";     
  13.     }  
  14. }
  15. int main()
  16. {
  17.     int n;
  18.     cout <<"Nhap n: ";
  19.     cin >> n;
  20.     cout<<"Day so fibonacci toi so thu "<<n<<": ";
  21.     DaySoFibonacci(n);
  22.     system("pause");
  23.     return 0;
  24. }
Add Comment
Please, Sign In to add comment