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

By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and

ID: 3857622 • Letter: B

Question

By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two;

Please use the code and don't change it:

#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;

// YOUR CODE GOES HERE

int main()
{
   int num;
   int fibb;
   cout << "Please enter a number between 5 and 22: ";
   cin >> num;
   cout << num << endl;
   if ((num < 5) || (num > 22))
       cout << "Please follow the directions!" << endl;
   else {
       fibb = fibonacci(num);
       cout << endl;
       cout << "Fibonacci # " << num << " is " << fibb << endl;
   }
}

By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two, for example, the first 6 Fibonacci numbers are 0, 1, 1, 2, 3, 5. Write a program that asks the user for a number between 5 and 22 (inclusive) and then displays that many Fibonacci numbers. YOU MUST write a function called fibonacci which is called from main as shown in the template. Note that the function adds up each of the Fibonacci numbers and returns the last one to main. Add a newline every 10th output value. For example: Please enter a number between 5 and 22: 12 011 2 3 5 8 13 21 34 55 89 Fibonacci # 12 is 144

Explanation / Answer

Our Code will be:

int fibonacci (int n) // passing number value while calling function

{

int c, first=0, second=1, next=0;

cou<<"First"<<n<<"terms of Fibonacci series are:"<<endl;

for (c=0; c<n; c++)

{

if ( c <= 1)

next = c;

else

{

next = first + second;

first = second;

second = next;

}

cout<<next;

}

cout<<"Fibonacci #"<<n<<"is""<<first+second;

return 0;

}