Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will calculate square and cube of numbers ranging from 0 to

ID: 3532763 • Letter: W

Question

Write a program that will calculate square and cube of numbers ranging from 0 to 10. Print the output like the following table (hint: use for loop, to print as a table use printf formatting for width).

Number        Square            Cube

0                     0                      0

1                     1                      1

2                     4                      8

3                     9                      27

4                    16                     64

5                    25                    125

6                    36                    216

7                    49                    343

8                    64                    512

9                    81                    729

10                  100                  1000

Explanation / Answer

//This is the easiest way to do it using just 1 for loop..

#include <iostream>

#include <iomanip>


using namespace std;

int main()

{

for (int i =0; i < 11; i++)

{

cout<<setw(2)<< i<<setw(10)<< i*i <<setw(12)<< i*i*i<< endl;

}

cout<< endl;

system("pause");

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote