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;

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 0 1 1 2 3 5 8 13 21 34 55 89 Fibonacci # 12 is 144 

Edit this code C++

#include

#include

#include

#include

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;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The initial answer is mostly correct but there are some issues to address Lets update the function a... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!