Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int Fibonacci(int n) {
- if (n < 0) {
- return -1;
- }
- else if (n == 0 || n == 1)
- {
- return n;
- }
- else {
- return Fibonacci(n - 1) + Fibonacci(n - 2);
- }
- }
- void Show(int n) {
- int i = 0;
- while ( Fibonacci(i) < n) {
- cout << Fibonacci(i);
- cout << " ";
- i++;
- }
- }
- int main() {
- int n;
- cout << "Nhap n: ";
- cin >> n;
- Show(n);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement