Cambridge O Level Computer Science 2210 · 7.7 Trace tables

Q51 · 2210/21/M/J/22 Q5

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.

Q512210/21/M/J/22original Q5Structured · 7 marks
Question 5 from 2210/21/M/J/22

Worked solution

(a)

Limit is the first input (8), so the loop runs 8 times, reading Value each time. Only 3-digit values are looked at. First is the first digit (Value DIV 100) and Last is the last digit (Value MOD 10). The value is output if they match.

CounterValueFirstLastLimitOUTPUT
008
166
260666606
36226
48448
564262
674777747
777
812111121

Counter and Limit columns correct [1]

Value column correct [1]

First column correct [1]

Last column correct [1]

OUTPUT column correct [1]

(b)

Look at what is output.

It checks for 3-digit numbers [1]

...and outputs those where the first and last digits are the same [1]

KEY IDEAIn a trace table, change a variable's column only on the line that changes it; unchanged values are left blank.
TOTAL 7 marks

Official mark scheme

Mark scheme for 2210/21/M/J/22 question 5
VIDEO
▶ Topic lesson

A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.