Study the following pseudocode. DECLARE Row : INTEGER DECLARE Col : INTEGER DECLARE Value : INTEGER Value ← 0 FOR Row ← 1 TO 3 FOR Col ← 1 TO Row ...

Assessment: Computer Science (9-1) 0984 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science (9-1) - 0984

Question 1 Report

Study the following pseudocode.

DECLARE Row : INTEGER
DECLARE Col : INTEGER
DECLARE Value : INTEGER
Value ← 0
FOR Row ← 1 TO 3
    FOR Col ← 1 TO Row
        Value ← Value + Col
        OUTPUT Value, " "
    NEXT Col
    OUTPUT ""  'new line
NEXT Row

(a) Complete the trace table showing all iterations. [4]

RowColValue (before)Value + ColValue (after)OUTPUT
11
21
22
31
32
33

Answer Details

(a) The nested loops iterate with Col running from 1 up to the current Row value. Value accumulates by adding Col each time. The complete trace:

RowColValue (before)Value + ColValue (after)OUTPUT
1100 + 1 = 111
2111 + 1 = 222
2222 + 2 = 444
3144 + 1 = 555
3255 + 2 = 777
3377 + 3 = 101010

The output appears on three lines: "1", then "2 4", then "5 7 10" (a newline is printed after each Row completes). Note that Value is cumulative across all rows, not reset per row. [4]

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