Cambridge O Level Computer Science 2210 · 7.7 Trace tables

Q61 · 2210/22/O/N/24 Q7

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

Q612210/22/O/N/24original Q7Structured · 8 marks
Question 7 from 2210/22/O/N/24

Worked solution

(a)

Run the REPEAT loop one input at a time. Answer starts as Value and is multiplied by Count from Value - 1 down to 1. Input -1 ends the algorithm, so 20, 9 and 4 are never read.

ValueCountAnswerOUTPUT
55
420
360
2120
1120120
66
530
4120
3360
2720
1720720
-1

Value column correct [1]

Count column correct [1]

Answer column correct down to the first OUTPUT (120) [1]

Answer column correct for the remaining rows [1]

OUTPUT column correct [1]

(b)

It works out the factorial of the input number: it multiplies the number by each whole number below it until 1 (for example 5 × 4 × 3 × 2 × 1). [1]

(c)

The loop would never end properly. Write two of these:

The program would accept the value and enter the FOR loop [1]

Count would keep going down by 1 and never reach 1, because it starts below 1, so there is an endless loop [1]

KEY IDEATrace each loop pass in order, and remember a FOR loop counting down needs a start value above its end value.
TOTAL 8 marks

Official mark scheme

Mark scheme for 2210/22/O/N/24 question 7
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.