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 ...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

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]

Answer Details

(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 Row

The 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]

RowProductsOutput line
11*1=1, 1*2=2, 1*3=3, 1*4=4, 1*5=51 2 3 4 5
22*1=2, 2*2=4, 2*3=6, 2*4=8, 2*5=102 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].

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning