Odd number series beginning a given number and given term count – CSKC
Sign In

Search

Solved Problem #CPP#2418    siteicon   siteicon  

Problem Statement - Odd number series beginning a given number and given term count

Write a program to print odd numbers series up to 20 terms beginning from 13.

Solution

TC++ #2418

 

×

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 t=13;  //The beginning number is declared in t and set equal to 13 as given in problem.
for(int tc=1;tc<=20;++tc)
The loop starts from 1 and goes upto 20 the term count given.

cout<<t<<” “;
The term is printed.

t+=2;
The next term is prepared by adding 2 to the previous number.

Notes

  • Notice that the index of loop and the term value calculation are being done in separate variables. This is the ideal approach for series printing questions.

Common Errors

  • If the term counting loop begins fro 0 then the condition check would be only < operator else if it begins from 1 the condition check would be <= operator. Students are advised to take additional care for such operators.


Share

Created: 9-Jan-2018 20:12 | Updated: 18-Dec-2018 18:47|