Problems: The terms of the Fibonacci sequence are the numbers the numbers 1, 2,
ID: 3802474 • Letter: P
Question
Problems: The terms of the Fibonacci sequence are the numbers the numbers 1, 2, 3, 5, 8, 13, The next term in the sequence is found by summing the previous two terms. Numbers in an sequence are formed by summing the previous three terms and subtracting 3. For example, the ACSLacd sequence starting with l, 0, and follows: l, 0, 4, 2, 3, 6, 8, 14, 25, ... Input: Five sets of data. Each set consists of four integers: a_1, a_2, a_3, sad N. The first three numbers are the first three terms of an ACSLacd sequence. The fourth number the term is the term to print. For each input se, print the Nth term of the ACSLacd sequence defined by the first three numbers in the input set. Sample Input: Line #1: 1, 0, 4, 9 Line #2 1, 1, 2, 5 Sample output: Output #1 25 output #2 1Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int first, second,third, term,i,next;
for(int j=0;j<5;j++){
cin>>first;
cin>>second;
cin>>third;
cin>>term;
for(i=3; i<term; i++)
{
next = first + second+third -3;
first = second;
second = third;
third=next;
}
cout<<"Output is #"<< j+1 << ": "<<third<<" ";
}
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.