IGCSE · Practice questions · Two-dimensional arrays and nested loops

Table it up.

Six original Cambridge-style questions on two-dimensional arrays and nested iteration, with mark points.

Original questions All questions on this page are original work, written in the Cambridge IGCSE style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Row first, then column.

01
Explain
[2 marks]

Describe a two-dimensional array.

  • A table-like data structure with rows and columns, under one identifier, all elements the same data type. ✓
  • Each element is accessed with two indexes: row and column. ✓
02
Write
[2 marks]

Write a declaration for a 2D array Seats that stores a CHAR for each seat in a cinema with 12 rows of 20 seats.

  • DECLARE Seats : ARRAY[1:12, 1:20] ✓
  • OF CHAR ✓
03
Trace
[3 marks]

State the values stored and the output.

FOR R ← 1 TO 2
    FOR C ← 1 TO 3
        Grid[R, C] ← R * C
    NEXT C
NEXT R
OUTPUT Grid[2, 3], " ", Grid[1, 2]
  • Row 1: 1, 2, 3. ✓
  • Row 2: 2, 4, 6. ✓
  • Output: 6 2 ✓
04
Write
[5 marks]

Marks[1:30, 1:4] stores 4 test marks for each of 30 students (one row per student). Write pseudocode that outputs each student's total mark.

  • FOR Student ← 1 TO 30 ✓
  • Total ← 0 inside the outer loop, before the inner loop ✓
  • FOR Test ← 1 TO 4 ... NEXT Test ✓
  • Total ← Total + Marks[Student, Test] inside the inner loop ✓
  • OUTPUT Student, Total after the inner loop, then NEXT Student ✓
05
Analysis
[2 marks]

A student puts RowTotal ← 0 before both loops in a row-total program. Explain the effect on the output.

  • RowTotal is never reset between rows. ✓
  • So each row's output is a running total that includes all previous rows; only the first row's total is correct. ✓
06
Apply
[3 marks]

Using the Sales table in this lesson (3 shops by 4 weeks), state (a) Sales[1, 2] (b) the total for week 4 (c) the total for shop 2.

  • (a) 8 ✓
  • (b) 6 + 7 + 8 = 21 ✓
  • (c) 3 + 9 + 4 + 7 = 23 ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.