9618/23/O/N/25 question 6: worked solution (October/November 2025, paper 23)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 11.1 Programming Basics Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3. Q37 9618/23/O/N/25 original Q6 Structured · 9 marks Worked solution (a) Write a list of test numbers chosen so that every possible check digit (0 to 9) is produced. [1] Run Generate() on each and check each result matches the expected value . [1] (b) Turn the number into a string. The last digit is the check digit. Add up all the other digits and compare their sum MOD 10 with the check digit. FUNCTION CheckNumber(Number : INTEGER) RETURNS BOOLEAN DECLARE Total, Index, CheckDigit : INTEGER DECLARE NumString : STRING Total ← 0 NumString ← NUM_TO_STR(Number) CheckDigit ← STR_TO_NUM(RIGHT(NumString, 1)) FOR Index ← 1 TO LENGTH(NumString) - 1 Total ← Total + STR_TO_NUM(MID(NumString, Index, 1)) NEXT Index IF Total MOD 10 <> CheckDigit THEN RETURN FALSE ENDIF RETURN TRUE ENDFUNCTION Function heading with name, parameter and return type [1] NUM_TO_STR used to convert the number [1] Check digit taken from the last digit [1] Loop for the length of the string minus 1 [1] Digits added correctly in the loop, with Total set to 0 before it [1] Check digit calculated from the sum (Total MOD 10) [1] Compared with the last digit and the correct BOOLEAN returned [1] Another way: no string, take the last digit with MOD 10, then use a WHILE loop with MOD and DIV on the rest. KEY IDEA Split off the last digit as the check digit, add up the other digits, and compare the sum MOD 10 with it. TOTAL 9 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by ZAINEMATICS. Tap the picture to open it on YouTube.