Printing Times Tables
Problem
Constraint: you can’t go back up or delete once your program has printed to the console. That means your program must print left to right, top to bottom.
Question: will the program print the table row by row? Or column by column?
Solution
#include <iostream>
using namespace std;
const int MAX_TABLE_SIZE = 9;
int main()
{
cout << "Here's your times tables" << endl;
// foreach row
for (int row = 1; row <= MAX_TABLE_SIZE; row++)
{
// foreach column in that row
for (int col = 1; col <= MAX_TABLE_SIZE; col++)
{
cout << (row * col) << "\t";
}
cout << endl << endl;
}
system("pause");
return 0;
}
Back to top