Advertisement
Guest User

Bài 1

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