int main()
{
int n, t1 = 0, t2 = 1,t3 = 2, nextTerm = 0;
cout << "Enter the number of terms: "; cin >> n;
cout << "Fibonacci number sequence up to " << n << ":" << endl;
for (int i = 1; i <= n+1; i++)
{
if (i == 1)
{
cout << " " << t1;
continue;
}
if (i == 2)
{
cout << " " << t2 << " ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm << "";
cout << endl;
}
cout << "Number of times iterative function is called: " << n * 3 << endl;
return 0;
}
Output:
Enter the number of terms: 5
Fibonacci number sequence up to 5:
0 1 1
2
3
5
Number of times iterative function is called: 15
I want the output to be:
Enter the number of terms: 5
Fibonacci number sequence up to 5:
0 1 1 2 3 5
Number of times iterative function is called: 15