Two previous terms addition series (like Fibonacci) from another number. – CSKC
Sign In

Search

Solved Problem #CPP#2413    siteicon   siteicon  

Problem Statement - Two previous terms addition series (like Fibonacci) from another number.

Assume that first two terms of a series are 10 and 11. Then use the Fibonacci series rules of adding two previous terms, write a program to print 10 terms of such a series. Also print the sum of all the terms printed.

Solution

TC++ #2413

 

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

  Related ( ? ) :

int t1=10,t2=11,term; //t1 and t2 are fixed at 10 and 11 as given in problem. term is declared.
cout<<t1<<” “<<t2<<” “; //First two terms are printed directly.
int tsum=t1+t2; //variable tsum declared and initialised with sum of first two terms.
for(int t=3;t<=10;++t)
Loop begins from 3rd terms and goes upto 10th term as desired.
{
term=t1+t2;  //The term from 3rd term onwards is calculated by adding two previous terms.
tsum+=term; //tsum is added with new term successively
cout<<term<<” “; //The term is printed.
t1=t2;  //previous term shifted to before previous term storage location.
t2=term; //current term shifted to previous term storage location.
}
cout<<endl<<“Sum of terms = “<<tsum<<endl;
Sum of terms is printed.

Notes

  • Terms not starting with 0 or 1 can not be called a Fibonacci series, but similar rule can definitely apply for any kind of series.

Common Errors

  • Careful initialisation of previous terms and then shifting of terms are desired.


Share

Created: 9-Jan-2018 19:14 | Updated: 18-Dec-2018 18:45|