Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q31 · 9618/22/O/N/23 Q2

Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2.

Q319618/22/O/N/23original Q2Structured · 7 marks
Question 2 from 9618/22/O/N/23

Worked solution

(a)

Draw the flowchart from START, using these shapes in order:

Process box: set Total to 0 (and a flag or similar to show 27 has not been seen) [1]

Input parallelogram: INPUT a number, then a decision diamond: is the number 27? If No, go back to the input. Only the first 27 switches summing on [1]

After 27 is found, a loop that keeps going until 0 is input: INPUT Number, then decision: is Number = 0? [1]

If No, a process box: Total ← Total + Number, then loop back to the input [1]

If Yes (0 input), output parallelogram: OUTPUT Total, then END [1]

(b)

Name: a conditional loop (a pre-condition WHILE loop or a post-condition REPEAT loop) [1]

Justification: the number of iterations is not known in advance, because the loop only stops when 0 is input [1]

KEY IDEAWhen a loop ends because of a special input rather than a set count, use a conditional loop.
TOTAL 7 marks

Official mark scheme

Mark scheme for 9618/22/O/N/23 question 2
VIDEO
▶ Starts at Q2 (8:53)

Starts at Q2 (8:53) · by Pseudocode Pro. 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.