Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int fibo(int n)
  4. {
  5.     if (n == 1 || n == 2)
  6.     {
  7.         //cout << 1;
  8.         return 1;
  9.     }
  10.     else
  11.         return fibo(n - 1) + fibo(n - 2);
  12.  
  13. }
  14. int main()
  15. {
  16.     int n;
  17.     int d=1;
  18.     cout<<" nhap n: ";
  19.     cin>>n;
  20.     while (d >= 1)
  21.     {
  22.         int k = fibo(d);
  23.         if (k <= n)
  24.         {
  25.             cout << k<<" ";
  26.             d++;
  27.         }
  28.         else break;
  29.     }
  30.     system("pause");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement