Write a program in c that calculates the cube of the first t

Write a program in c++ that calculates the cube of the first ten natural numbers.

Solution

#include<iostream>

using namespace std;

int main()
{
   int cube;
   //cube of first natural numbers 1,2,3,4,5,6,7,8,9,10
   for (int i = 1; i <= 10; i++)
   {
       //multiply same number thrice to get cube of a number
       cube = i * i * i;
       cout << \"Cube of \" << i << \" = \" << cube << endl;
   }
}

-------------------------------------------------------------------

output:

Cube of 1 = 1
Cube of 2 = 8
Cube of 3 = 27
Cube of 4 = 64
Cube of 5 = 125
Cube of 6 = 216
Cube of 7 = 343
Cube of 8 = 512
Cube of 9 = 729
Cube of 10 = 1000

Write a program in c++ that calculates the cube of the first ten natural numbers.Solution#include<iostream> using namespace std; int main() { int cube; //

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site