Advertisement
Guest User

Câu 1: In ra dãy số Fibonaci tới số thứ n

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