Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 8 of 8.
Use a loop for 500 numbers, check each is a whole number from 1 to 999, and keep the largest and smallest.
Large ← 0
Small ← 1000
FOR Count ← 1 TO 500
REPEAT
OUTPUT "Enter a whole number between 1 and 999"
INPUT Number
UNTIL Number >= 1 AND Number < 1000 AND Number = Number DIV 1
IF Number < Small
THEN
Small ← Number
ENDIF
IF Number > Large
THEN
Large ← Number
ENDIF
NEXT Count
Range ← Large - Small
OUTPUT "Largest number is ", Large
OUTPUT "Smallest number is ", Small
OUTPUT "Range of numbers is ", RangeLarge and Small given starting values before the loop [1]
A loop that runs 500 times [1]
Input of a number with a prompt [1]
A working range check for 1 to 999 [1]
The largest number selected [1]
The smallest number selected [1]
Any six points score. Also credited: a check for a whole number, working out the range, and outputting the largest, smallest and range with a message.
Write the action and the method:
Action: reduce the number of numbers entered [1]
Method: decrease the final value of the loop [1]
Another answer that scores both marks: remove the need to input values by using random numbers or a previously filled array.
▶ Whole paper
Video solution of the whole paper · by CS BY AQIB KHAN. 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.