#include <iostream>
void fibonacci(int n) {
int first = 0, second = 1, next;
std::cout << "Fibonacci Series up to " << n << " terms:" << std::endl;
for (int i = 0; i < n; i++) {
if (i <= 1)
next = i;
else {
next = first + second;
first = second;
second = next;
}
std::cout << next << " ";
}
std::cout << std::endl;
}
int main() {
int n;
std::cout << "Enter the number of terms for Fibonacci series: ";
std::cin >> n;
fibonacci(n);
return 0;
}
03-20
1万+