Gap increment series – CSKC
Sign In

Search

Solved Problem #CPP#2422    siteicon   siteicon  

Problem Statement - Gap increment series

Write a program to print the following series up to 15 terms ..
1 4 8 13 19 26 …….

Solution

TC++ #2422

 

×

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

When we observe the series 1 4 8 13 19 26 …… we observe that the first gap is 3 and then the gap increases by 1 as the series progresses. Here we use an additional gap modifier variable as follows.

int term=1,gapm=0;
The term  begins at 1 and then adjusted by the formula within the loop. The gapm variable shall be use to modify the gap as the series progresses. For first term no modification is required to we initialise it to 0

for(int tc=1;tc<=15;++tc) //This runs from 1 to 15 the term count
{
cout<<term<<” “; //The first term is printed as such.
term=term+3+gapm++; //Next term calculation is done with addition of 3 and incrementing the gapm variable. In the first iteration it will be 0 and then 1, 2, 3 on wards.
}

Notes

  • The gapm is just like an additional variable for series progression modifiers. One can have many such variables for complex series patterns.


Share

Created: 9-Jan-2018 20:49 | Updated: 18-Dec-2018 18:52|