Cambridge AS Level Computer Science 9618 · 10.2 Arrays

Q36 · 9618/22/M/J/25 Q4

Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.

Q369618/22/M/J/25original Q4Structured · 6 marks
Question 4 from 9618/22/M/J/25

Worked solution

Draw the flowchart in this order. The first loop reads the values and the second loop outputs them backwards.

START → box: SET Count TO 1 → decision: IS Count = 101 ?

Index (Count) set to 1 (or 0) before the first loop [1]

Loop that runs 100 times (decision Count = 101, with NO going round the loop) [1]

On NO: parallelogram INPUT Value [1]

Then box SET Number[Count] TO Value, then box Increment Count, then back to the decision [1]

On YES: box SET Count TO 100, then decision IS Count = 0 ? so the output loop starts at the last element [1]

On NO: parallelogram OUTPUT Number[Count], then box Decrement Count, then back to the decision; on YES go to END, so every element is output once in reverse order [1]

KEY IDEAUse one counter loop going up to store the values and a second loop going down to output them in reverse.
TOTAL 6 marks

Official mark scheme

Mark scheme for 9618/22/M/J/25 question 4
VIDEO
▶ Whole paper

Video solution of the whole paper · by Awab Aqib. 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.