Small Multiplication Table
0.5s 256MMultiplication tables help us quickly see the result of multiplying two numbers.
You are given an integer \(n\). Output the multiplication table from \(1 \times 1\) to \(n \times n\) in order. First fix the outer number as \(1\) and let the inner number go from \(1\) to \(n\); then fix the outer number as \(2\) and let the inner number go from \(1\) to \(n\) again. Continue until the outer number reaches \(n\).
Each multiplication expression must be printed on its own line, exactly in the required format.
Syntax Restrictions
This problem uses the syntax restrictions of Unit 4 (Loops) of the syntax textbook. You may use if, else, loops, comparisons, logical operators, integer variables, cin, cout, and cout << endl; however, you may not use arrays or containers, and you may not use any function other than main (including built-in functions and user-defined functions). The name endl is allowed only as an output newline manipulator, not as a function call.
Your source code is checked automatically during judging. A submission that breaks the restrictions is judged SR (Syntax Restriction), and the judge feedback lists where the violation is.
Click to expand: allowed and forbidden syntax
Allowed:
#include <iostream>or other ordinary includes (no extra header is needed)using namespace std;- the
int main()function andreturn 0; - integer, Boolean, and character variables, such as
int,long long,bool, andchar - reading with
cin >>and printing withcout <<, includingcout << endl if,else,for, andwhile- arithmetic, comparison, and logical operators, such as
+,-,*,/,%,<,<=,==, and&& - assignment and increment/decrement, such as
=,+=,++, and-- - comments (
//and/* */)
Forbidden (common examples):
- arrays and indexing syntax
[] - containers or similar tools such as
vector,array,string,deque,map, andset - dynamic allocation syntax such as
newanddelete - any function call or function declaration other than
main, includingmax,min,abs,sqrt,pow,sort,swap,getline,printf, andscanf - non-include preprocessor directives such as
#define
Input
The input contains one line with one integer \(n\).
Constraints
- \(1 \le n \le 9\)
Output
Output \(n \times n\) lines.
For each pair \(i, j\), output one line:
i*j=answer
Replace i, j, and answer with the actual numbers. Do not print spaces around * or =.
The required order is:
- First fix \(i = 1\) and let \(j\) go from \(1\) to \(n\).
- Then fix \(i = 2\) and let \(j\) go from \(1\) to \(n\).
- Continue in this way until \(i = n\).
Sample Input 1
3
Sample Output 1
1*1=1
1*2=2
1*3=3
2*1=2
2*2=4
2*3=6
3*1=3
3*2=6
3*3=9
Sample Explanation 1
Since \(n = 3\), we output the multiplication table from \(1 \times 1\) to \(3 \times 3\).
Sample Input 2
1
Sample Output 2
1*1=1
Log in to write and submit code. Creating an account is free.