Programming · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 13% of your exam marks.
Paper 2 is almost entirely programming. Variable types, assignments, loops and conditionals are tested every session.
CIE pseudocode supports the standard arithmetic operators, plus two specific to integer division.
| Operation | Pseudocode | Python |
|---|---|---|
| Addition | + | + |
| Subtraction | - | - |
| Multiplication | * | * |
| Division |
CIE pseudocode uses only these operators: +, -, *, /, and the two integer-division operators MOD and DIV. There is no exponentiation operator in CIE pseudocode, so repeated multiplication is written out (for example x * x * x for "x cubed").
DIV returns the whole-number part of a division, throwing away any remainder.
17 DIV 5 = 3 (because 17 ÷ 5 = 3 remainder 2)
20 DIV 4 = 5 (because 20 ÷ 4 = 5 exactly)
9 DIV 2 = 4 (because 9 ÷ 2 = 4 remainder 1)
Useful for splitting things into equal groups: "how many full minutes are in 130 seconds?" → 130 DIV 60 = 2.
MOD returns the remainder after a division.
17 MOD 5 = 2 (17 ÷ 5 = 3 remainder 2)
20 MOD 4 = 0 (20 ÷ 4 = 5 remainder 0)
9 MOD 2 = 1 (9 ÷ 2 = 4 remainder 1)
Useful for a classic check: "is N divisible by 2?" → N MOD 2 = 0 is true for even numbers.
ROUND(value, places)returnsvaluerounded toplacesdecimal places.
ROUND(3.14159, 2) = 3.14 (two decimal places)
ROUND(8.6, 0) = 9 (zero decimal places: nearest whole number)
value should be a real number and places a whole number. ROUND is useful for tidying up money or measurements before they are output.
RANDOM()returns a random real number between 0 and 1 inclusive. It takes no arguments.
To get a random whole number in a range, scale the result and round it. For example, a random whole number from 0 to 6 is ROUND(RANDOM() * 6, 0). RANDOM() is the standard way to add chance to a program, such as rolling a dice or shuffling.
Using DIV and MOD together to split a total
A checkout system stores a total price in whole pence. Convert 503 pence into pounds and pence (e.g. £5.03).
Solution:
503 DIV 100 = 5 (integer quotient: how many complete hundreds fit)503 MOD 100 = 3 (the remainder after removing those complete hundreds)The same pattern applies any time a total must be split into a larger unit and a leftover: total items DIV group-size gives the number of complete groups; total items MOD group-size gives what is left over.
/ |
/ |
| Integer division (quotient) | DIV | // |
| Modulus (remainder) | MOD | % |