I need this answered asap. You can use the libraries seen below here only. Also
ID: 3857517 • Letter: I
Question
I need this answered asap. You can use the libraries seen below here only. Also only fill in the " your code goes here part".
#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;
}
}
2.10 Problem 12.3 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 0112 35813 21 34 55 89 Fibonacci # 12 is 144 LAB 1/22 ACTIVITY 12.10.1: Problem 12.3Explanation / Answer
// Fibonacci # 12 is 89 NOT 144
main.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
using namespace std;
int fibonacci(int n)
{
int t1 = 0, t2 = 1, nextTerm = 0;
for (int i = 1; i <= n; ++i)
{
if( (i-1) % 10 == 0)
{
cout<<endl;
}
if(i == 1)
{
cout << " " << t1;
continue;
}
cout<<" ";
if(i == 2)
{
cout << t2 << " ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm << " ";
}
return nextTerm;
}
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;
}
}
Output :-
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.