using namespace std;
int nextTerm(int n){
int firstTerm = 0, secondTerm = 1;
int nextTerm;
cout << "Fibonacci Series: " << firstTerm << " " << secondTerm << " ";
for (int i = 1; i <= n-2; ++i) {
nextTerm = firstTerm + secondTerm;
cout<<nextTerm << " ";
firstTerm = secondTerm;
secondTerm = nextTerm;
}
}
int main() {
int n;
cout << "Enter number of terms: ";
cin >> n;
nextTerm(n);
return 0;
}
Comments
Post a Comment