Cambridge O Level Computer Science 2210 · 8.2 Arrays

Q57 · 2210/23/O/N/24 Q6

Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 2 of 3.

Q572210/23/O/N/24original Q6Structured · 9 marks
Question 6 from 2210/23/O/N/24

Worked solution

(a)

The loop counts values until A[C] is 0, so C must start at 1, W is the running total, and X is the average.

Line 06: C ← 1 [1]

Line 08: W ← W + A[C] [1]

Line 11: X ← W / (C - 1) (ROUND(W / (C - 1), 0) is also accepted) [1]

(b)

The number of values is C - 1, because C ends one past the last value.

OUTPUT "Number of values stored in the array: ", C - 1
OUTPUT "Average of the values stored: ", X

Output of the number of values (C - 1) [1]

Output of the average X [1]

Suitable messages with both outputs [1]

(c)

Write a name that says what each item holds.

Array A: Values (or similar) [1]

Variables, any suitable names, for example C: Index, X: Average, W: Total. Three suitable names score 2 marks, one or two score 1 mark. [2]

KEY IDEACounter starts at 1, total adds each value, and the count of values is one less than the final counter.
TOTAL 9 marks

Official mark scheme

Mark scheme for 2210/23/O/N/24 question 6
VIDEO
▶ Topic lesson

A lesson on this topic · by Craig'n'Dave. 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.