#include using namespace std; // file: pow2.cpp // while loops, functions, width // while loops // example for creating a math table int pow(int num, int exp) // precondition: reasonable int num and // small positive int exp // postcondition: returns num^exp { int prod = 1, i = 0; while (i < exp) { prod *= num; i++; } return prod; } int main() { int size, j = 0; cout << "Specify table size (be modest!): "; cin >> size; cout << " N N^2 N^3 N^4 N^5 N^6" << endl; while ( j < size) { j++; cout.width(3); cout << j ; cout.width(5); cout << pow(j, 2); cout.width(6); cout << pow(j, 3); cout.width(7); cout << pow(j, 4); cout.width(8); cout << pow(j, 5); cout.width(10); cout << pow(j, 6) << endl; } return 0; } /* prompt> pow2 Specify table size (be modest!): 20 N N^2 N^3 N^4 N^5 N^6 1 1 1 1 1 1 2 4 8 16 32 64 3 9 27 81 243 729 4 16 64 256 1024 4096 5 25 125 625 3125 15625 6 36 216 1296 7776 46656 7 49 343 2401 16807 117649 8 64 512 4096 32768 262144 9 81 729 6561 59049 531441 10 100 1000 10000 100000 1000000 11 121 1331 14641 161051 1771561 12 144 1728 20736 248832 2985984 13 169 2197 28561 371293 4826809 14 196 2744 38416 537824 7529536 15 225 3375 50625 759375 11390625 16 256 4096 65536 1048576 16777216 17 289 4913 83521 1419857 24137569 18 324 5832 104976 1889568 34012224 19 361 6859 130321 2476099 47045881 20 400 8000 160000 3200000 64000000 */