Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.
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.
| Counter | Value | First | Last | Limit | OUTPUT |
|---|---|---|---|---|---|
| 0 | 0 | 8 | |||
| 1 | 66 | ||||
| 2 | 606 | 6 | 6 | 606 | |
| 3 | 6226 | ||||
| 4 | 8448 | ||||
| 5 | 642 | 6 | 2 | ||
| 6 | 747 | 7 | 7 | 747 | |
| 7 | 77 | ||||
| 8 | 121 | 1 | 1 | 121 |
Counter and Limit columns correct [1]
Value column correct [1]
First column correct [1]
Last column correct [1]
OUTPUT column correct [1]
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]
▶ 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.