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: 3642130 • 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.

The output should work when the input numbers are:

0
1
2
-1, -100, 3
10
11
12
13

Explanation / Answer

This program is much better because it works with large numbers. The above program will bog down with the number of recursive calls if you enter something bigger than 35 or so. Try it out and see. #include using namespace std; int fibo(unsigned int n) { //n_minus_1 represents what's supposed to be F(n-1) //n_minus_2 represents what's supposed to be F(n-2) //sum represents F(n) which equals F(n-1)+F(n-2) double n_minus_1=0,n_minus_2=1,sum; switch(n) { //if n=0 then F(n)=0 case 0: return 0; //if n=1 then F(n)=1 case 1: return 1; //otherwise the sum (i.e F(n)) is equal to (n_minus_1)+(n_minus_2) (i.e F(n-1)+F(n-2) //the counter keeps on moving the variables areound 'n' times //so that on each time F(n-2) becomes equal to F(n-1) and F(n-1) becomes equal to F(n) //and F(n) is reevaluated each time in the loop default: for(int counter=0;counter