Series building concept with different term expression builder and term counter
It is possible to build many series expression easily when we take different variables for term counting and term expression building.
Learning Objectives
- Learning to solve series problems by separating term count counter and the expression building procedure. This helps to write series in a more generic way.
Source Code
|
|
Run Output
Code Understanding
Here we are trying to build a series for 10 terms with a term expression like follows –
5^2 7^2 9^2 ………… upto 10 terms.
int no_of_terms=10;
Here we define a separate variable for no_of_terms so that loop condition can be checked against this variable.
int tbase=5;
This is the base value for starting of series.
int texp=tbase;
The term expression is formed on the basis of this base value.
for(int tc=1;tc<=no_of_terms;++tc)
The loop starts from 1st term count for value specified upto no_of_terms.
int term=texp*texp;
The terms is built by arithmetic expressions on various term expressions.
cout<<term<<” “;
This printing of term.
texp+=2;
this is rebuilding of condition for forming another term. Here we find that the difference between base values is 2 so we write as above.
Notes
- Series based on arithmetic formulations can easily be written with the above method.
Common Errors
- Care must be taken in identifying the formula once a series is observed.
Suggested Filename(s): series-termx.cpp
Created: 8-Jan-2018 18:35 | Updated: 15-Sep-2018 12:47|
