Worked solution from the Programming Paper 2 Algorithms, Programming and Logic booklet, Part 2 of 3.
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]
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]
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]
▶ 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.