9618/22/M/J/22 question 2: worked solution (May/June 2022, paper 22)

Show as plain text

Cambridge AS Level Computer Science 9618 · 9.2 Algorithms Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2. Q19 9618/22/M/J/22 original Q2 Structured · 4 marks 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 IDEA Set 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 VIDEO ▶ Whole paper Video solution of the whole paper · by Awab Aqib. Tap the picture to open it on YouTube.