RUN


Program in C++ to display the cube of the number up to given an integer

Given: User will input number of terms and we have to print its cube till the given number of terms.

Example:

Input the number of terms : 4                                          

Number is: 1 and its cube is: 1                                  

Number is: 2 and its cube is: 8                                  

Number is: 3 and its cube is: 27                                 

Number is: 4 and its cube is: 64

# Algorithm

  1. Take the number of terms as input from the user.
  2. Start loop from i =1 to i<= n
  3. Cube= i*i*i    

  4. Print number and its cube as result.

Code:

// C++ program to display the cube of the numbers upto a given integer

#include <iostream>
using namespace std;

int main()

{

  int i, n, cube;
  cout << "Input the number of terms : ";
  cin >> n;

  for (i = 1; i <= n; i++){

    cube = i * i * i;
    cout << "Number is: " << i << " and its cube is: " << cube << endl;
  }

}

Report Error/ Suggestion

Related Posts:


CopyRight © 2020

CopyRight © 2020