Cambridge AS Level Computer Science 9618 · 9.2 Algorithms

Q19 · 9618/22/M/J/22 Q2

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

Q199618/22/M/J/22original Q2Structured · 4 marks
Question 2 from 9618/22/M/J/22

Worked solution

Draw the flowchart as follows. After START:

Set Count to 0 before the loop, then in the loop INPUT NextNum [1]

Decision Is NextNum < 0 ? : on YES go to the output box OUTPUT "Number of primes: ", Count (a message plus the count), then END [1]

On NO: a function call box Set Answer to IsPrime(NextNum) [1]

Decision Is Answer = TRUE ? : on YES Set Count to Count + 1; both YES and NO then go back to INPUT NextNum [1]

KEY IDEASet the counter before the loop, test the input to leave the loop, and count only when the function returns TRUE.
TOTAL 4 marks

Official mark scheme

Mark scheme for 9618/22/M/J/22 question 2
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.