List of all available Websheets
Viewing cpp/control/timestable by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Write a program that prints out a multiplication table. It should take an input <tt>n</tt>. The output should have <tt>n</tt> rows and <tt>n</tt> columns, and be formatted in 4-space wide columns, like this example output when the input <tt>n</tt> is 5: <pre> 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 </pre> Use <tt>cout << setw(4) << [thing you want to print]</tt> with each item printed, in order to get the column-based layout. |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; int main() { // get the input int n; cin >> n; // to print out fixed-width columns, print out each item with // cout << setw(4) << "item"; // see page 49 \[ for (int j=1; j<=n; j++) { // print items in a row for (int i=1; i<=n; i++) cout << setw(4) << i*j; // end the row cout << endl; } ]\ return 0; } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "5"}, {"stdin": "10"}, {"stdin": "15"} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.