Question 1 Report
A program needs to display a multiplication table for numbers 1 to 5. The output should be neatly aligned in columns.
Expected output:
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(a) Write pseudocode to produce this multiplication table. [4]
(b) Trace the output for the first two rows of the table, showing what is printed at each step. [2]
(c) Explain how you would modify the algorithm to produce a 10x10 multiplication table instead. [1]
(d) State one change needed if the table should show products up to 12 x 12. [1]
(a) The algorithm uses nested FOR loops to generate a multiplication table for numbers 1 to 5. [4]
DECLARE Row : INTEGER
DECLARE Col : INTEGER
DECLARE Product : INTEGER
FOR Row ← 1 TO 5
FOR Col ← 1 TO 5
Product ← Row * Col
OUTPUT Product, " "
NEXT Col
OUTPUT ""
NEXT RowThe outer loop controls the row (the first factor) and the inner loop controls the column (the second factor) [1]. OUTPUT "" after the inner loop moves to a new line [1].
(b) Trace of the first two rows: [2]
| Row | Products | Output line |
|---|---|---|
| 1 | 1*1=1, 1*2=2, 1*3=3, 1*4=4, 1*5=5 | 1 2 3 4 5 |
| 2 | 2*1=2, 2*2=4, 2*3=6, 2*4=8, 2*5=10 | 2 4 6 8 10 |
(c) Change both loop upper bounds from 5 to 10: FOR Row ← 1 TO 10 and FOR Col ← 1 TO 10 [1].
(d) Change both upper bounds to 12 and widen the column spacing since products can reach three digits (up to 12 * 12 = 144) [1].
Everything you need to excel in your exams