(Table) Using the techniques of this chapter, write a program that calculates the squares and cubes of the integers from 0 to 10. Use tabs to print the following neatly formatted table of values:
Solution:
Solution:
12345678910111213141516171819202122#include <iostream> using std::cin; using std::cout; using std::endl; int main() { cout << "integer\t\tsquare\t\tcube\n"; cout << 0 << "\t\t" << 0*0 << "\t\t" << 0*0*0 << "\n"; cout << 1 << "\t\t" << 1*1 << "\t\t" << 1*1*1 << "\n"; cout << 2 << "\t\t" << 2*2 << "\t\t" << 2*2*2 << "\n"; cout << 3 << "\t\t" << 3*3 << "\t\t" << 3*3*3 << "\n"; cout << 4 << "\t\t" << 4*4 << "\t\t" << 4*4*4 << "\n"; cout << 5 << "\t\t" << 5*5 << "\t\t" << 5*5*5 << "\n"; cout << 6 << "\t\t" << 6*6 << "\t\t" << 6*6*6 << "\n"; cout << 7 << "\t\t" << 7*7 << "\t\t" << 7*7*7 << "\n"; cout << 8 << "\t\t" << 8*8 << "\t\t" << 8*8*8 << "\n"; cout << 9 << "\t\t" << 9*9 << "\t\t" << 9*9*9 << "\n"; cout << 10 << "\t\t" << 10*10 << "\t\t" << 10*10*10 << "\n"; return 0; }
Post A Comment:
0 comments: