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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.