Cube series – CSKC
Sign In

Search

Solved Problem #CPP#2420    siteicon   siteicon  

Problem Statement - Cube series

Write a program to print the following series up to 15 terms ..
1 8 27 64 125 …….

Solution

TC++ #2420

 

×

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

If we watch the series 1 8 27 64 125 carefully we will see that it is a cube series of natural numbers. Now the code shall be built as follows.

int tbase=1;  //The base number we initialise as 1 which we will increment inside the loop
int term; //This variable is to print the term
for(int tc=1;tc<=15;++tc) //This loop begins at one and goes up to term count required.
{
term=tbase*tbase*tbase;  //Here the base value shall be cubed and the term will be deduced.
cout<<term<<” “; //Term shall be printed here.
tbase++;  //The new term base will be prepared here.
}

Notes

  • Generic method of series building can be used in such examples. Focus should be deducting the right formula.


Share

Created: 9-Jan-2018 20:35 | Updated: 18-Dec-2018 18:50|