Question:
Write a program that calculates the squares and cubes of the numbers from 0 to 10 and uses tabs to print the following table of values:
Answer:
#include <iostream>
using namespace std;
int main()
{
int num;
num = 0;
cout << "\nnumber\tsquare\tcube\n"
<< num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << "\n";
num = num + 1;
cout << num << '\t' << num * num << '\t' << num * num * num << endl;
return 0;
}
No comments:
Post a Comment