Programming Concepts
Programming · 4 question types
Exam Frequency Analysis
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 functions specific to integer division.
| Operation | Pseudocode | Python |
|---|---|---|
| Addition | + | + |
| Subtraction | - | - |
| Multiplication | * | * |
| Division | / | / |
| Exponentiation (raised to power) | ^ | ** |
| Integer division (quotient) | DIV(a, b) | // |
| Modulus (remainder) | MOD(a, b) | % |
CIE pseudocode uses these operators: +, -, *, / and the exponentiation operator ^, plus the two integer-division operations DIV and MOD, which are written as function calls: DIV(a, b) and MOD(a, b). The ^ operator raises a number to a power (for example 2 ^ 3 = 8, and X ^ 3 for "X cubed").
DIV: integer division
DIV(a, b)returns the whole-number part ofadivided byb, throwing away any remainder.
DIV(17, 5) returns 3 // 17 ÷ 5 = 3 remainder 2
DIV(20, 4) returns 5 // 20 ÷ 4 = 5 exactly
DIV(9, 2) returns 4 // 9 ÷ 2 = 4 remainder 1
Useful for splitting things into equal groups: "how many full minutes are in 130 seconds?" → DIV(130, 60) returns 2.
MOD: remainder
MOD(a, b)returns the remainder afterais divided byb.
MOD(17, 5) returns 2 // 17 ÷ 5 = 3 remainder 2
MOD(20, 4) returns 0 // 20 ÷ 4 = 5 remainder 0
MOD(9, 2) returns 1 // 9 ÷ 2 = 4 remainder 1
Useful for a classic check: "is a number divisible by 2?" → MOD(Number, 2) = 0 is true for even numbers.
ROUND: rounding to a number of decimal places
ROUND(value, places)returnsvaluerounded toplacesdecimal places.
ROUND(3.14159, 2) returns 3.14 // two decimal places
ROUND(8.6, 0) returns 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(): a random number
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:
- Whole pounds =
DIV(503, 100)= 5 (integer quotient: how many complete hundreds fit) - Remaining pence =
MOD(503, 100)= 3 (the remainder after removing those complete hundreds) - Result: £5.03
The same pattern applies any time a total must be split into a larger unit and a leftover: DIV(TotalItems, GroupSize) gives the number of complete groups; MOD(TotalItems, GroupSize) gives what is left over.