Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cs-142:printing-times-tables [2015/05/14 18:00] (current)
cs142ta created
Line 1: Line 1:
 +=Printing Times Tables=
 +==Problem==
 +*Print the 9 x 9 times table
  
 +* 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?
 +
 +* How does your brain tell your hand how to write a times table?
 +
 +==Solution==
 +<code cpp>
 +#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;
 +}
 +</​code>​
cs-142/printing-times-tables.txt · Last modified: 2015/05/14 18:00 by cs142ta
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0