Write a program using a for loop to display the cube of the numbers up to an integer entered by the user. Only a single for loop is required for this exercise.
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
#include<iostream>
using namespace std;
int main()
{
//prompt the user to enter an integer
int my_integer;
cout<<"\nEnter an integer: ";
cin>>my_integer;
cout<<"\nThe following are the cubes of numbers from 1 upto your integer "<<my_integer<<"\n"<<endl;
for(int i = 1; i<=my_integer;i++)
{
cout<<(i*i*i)<<" ";
}
cout<<"\n"<<endl;
return 0;
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment