Untitled
unknown
plain_text
2 years ago
438 B
6
Indexable
#include <iostream> using namespace std; int fibonacci(int n) { if (n <= 1) { return n; } return fibonacci(n - 1) + fibonacci(n - 2); } int main() { int n; cout << "Enter the value of n: "; cin >> n; cout << "Fibonacci sequence up to " << n << " terms:" << endl; for (int i = 1; i <= n; i++) { cout << fibonacci(i) << " "; } cout << endl; return 0; }
Editor is loading...