Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4.
Use one loop through all 100 elements. Add each element to the odd total or the even total, using MOD 2 to decide. Then compare the totals after the loop.
FUNCTION Check() RETURNS STRING
DECLARE Odd, Even, Index : INTEGER
Odd ← 0
Even ← 0
FOR Index ← 1 TO 100
IF Index MOD 2 = 0 THEN
Even ← Even + Data[Index]
ELSE
Odd ← Odd + Data[Index]
ENDIF
NEXT Index
IF Odd > Even THEN
RETURN "Odd"
ELSE
IF Even > Odd THEN
RETURN "Even"
ELSE
RETURN "Same"
ENDIF
ENDIF
ENDFUNCTIONFunction heading, RETURNS STRING and ENDFUNCTION [1]
Local variables Odd, Even and Index declared as INTEGER [1]
Odd and Even initialised to 0 [1]
Loop that runs 100 times (through the array) [1]
Odd and Even totals added up inside the loop [1]
Totals compared after the loop and the correct string returned [1]
▶ Starts at Q4 (32:47)
Starts at Q4 (32:47) · by Pseudocode Pro. 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.