/* ************************************************************************** * Program name : 013_Multiplication_table (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/08 - first version * ************************************************************************** * Description : (a) Input an integer number * * (b) Output the multiplication table * ************************************************************************** */ #include #include #include int main() { // part 1 : declaration int Inputnum, Index1, Index2; char again; // part 2 do { // (a) input an integer do { cout << "Please enter an integer number from 9 to 16 : "; cin >> Inputnum; } while (Inputnum<9 || Inputnum>16); // Note (1) // (b) output cout << "\n\n "; // Note (2) for (Index1=1; Index1<=Inputnum; Index1++) cout << setw(4) << Index1; cout << "\n "; // Note (3) for (Index1=1; Index1<=(Inputnum+1); Index1++) cout << setw(4) << "----"; cout << "\n"; for (Index1=1; Index1<=Inputnum; Index1++) // Note (4) { cout << setw(4) << Index1 << " |"; // Note (5) for (Index2=1; Index2<=Inputnum; Index2++) cout << setw(4) << Index1*Index2; // Note (6) cout << "\n"; // Note (7) }; // (c) try another number ? cout << "\a\n\nTry another number (Y/N) : "; cin >> again; } while (again=='Y' || again=='y'); cout << "\n\n" << endl; system("PAUSE"); return 0; } /* Notes (1) Limits the size of the multiplication table to be within the range 9 to 16. (2) Output a list of number as the header line of the table. (3) Draw a line to separate the table header and content. (4) Outer 'for' loop (5) Output the row number and a vertical line. (6) Inner 'for' loop to output each values in the table. (7) Jump to next line when a row of data is printed. */