Series based on x^2+x+1 – CSKC
Sign In

Search

Code Learning #CPP#2367    siteicon   siteicon  

Series based on x^2+x+1

Writing 10 terms of a series based on x^2+x+1 where x is taken from user.

Learning Objectives

  • Learning to write series terms based on common formula using a generic method of series.

Source Code

TC++ #2367

 

Source Code

×

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 ( ? ) :

Code Understanding

int no_of_terms=10;
Number terms is given here so that loop condition can be checked against it.

int x; cout<<“Give x for x^+x+1 series :”; cin>>x;
Collecting the value of x for the given series.

int tbase=x; //Using the value of x in the generic formula

int texp=tbase; //The expression writing term is initialised with the base value.

for(int tc=1;tc<=no_of_terms;++tc)
The loop starting from 1 to no_of_terms is run

int term=texp*texp+texp+1;
The series terms is built on the given formula.

cout<<term<<” “;
The terms is printed here.

texp+=1;
The term expression step is given here for preparing the next term.

Notes

  • This format can be used for most series formulas easily if the series formulas is known. In some cases many formulas can evolve for the same series. For e.g.
    x^2+2 can give 3, 6, 11, 18, 27, 38, 51, 66, 83, 102  and
    it can also be done in a way of adding 3, 5, 7, 9, 11 in the previous term.


Suggested Filename(s): series-exp1.cpp



Share

Created: 8-Jan-2018 22:35 | Updated: 15-Sep-2018 12:48|