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
- Take the number of terms as input from the user.
- Start loop from i =1 to i<= n
- Print number and its cube as result.
Cube= i*i*i
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