Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Write a program to print the following series up to 15 terms ..
1 4 8 13 19 26 …….
Solution
TC++ #2422
Run Output
1 4 8 13 19 26 34 43 53 64 76 89 103 118 134
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.