Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

See the description of the definition of the Fibonacci number sequence on the fo

ID: 3644492 • Letter: S

Question

See the description of the definition of the Fibonacci number sequence on the following link: http://en.wikipedia.org/wiki/Fibonacci_number

You only need to read the first three paragraphs.

You are to write a program that asks the use to enter an integer n and then print out the Fibonacci sequence that ends with the number Fn. The integer n must be greater than or equal to zero.Your program must have a function that calculates and prints the Fibonacci sequence.

Please do not forget to insert the commas and the ! Output must look exactly how it is written below.

Standard Input
0

Standard Output
Which Fibonacci number do you want to find?
0...

Standard Input
1

Standard Output
Which Fibonacci number do you want to find?
0, 1...

Standard Input
2

Standard Output

Which Fibonacci number do you want to find?
0, 1, 1...

Standard Input
-1
-100
3

Standard Output
Which Fibonacci number do you want to find?
The number entered must be greater than or equal to zero
Which Fibonacci number do you want to find?
The number entered must be greater than or equal to zero
Which Fibonacci number do you want to find?
0, 1, 1, 2...

Standard Input

10

Standard Output
Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55...

Standard Input

11

Standard Output
Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...

Standard Input

12

Standard Output

Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144...

Standard Input
13

Standard Output

Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233...

Explanation / Answer

Please rate...

#include<iostream>
using namespace std;
int main()
{
    int a,b,c=-1,d=0;
    while(c<0)
    {
        cout<<"Which Fibonacci number do you want to find?";
        cin>>c;
        if(c<0)cout<<"The number entered must be greater than or equal to zero ";
    }
    a=0;b=1;
    cout<<a;
    a=a+b;
    while(true)
    {
        if(d<=c-1){cout<<", "<<a;d++;}
        else break;
        a=a+b;
        if(d<=c-1){cout<<", "<<b;d++;}
        else break;
        b=a+b;
    }
    cout<<"... ";
}