30.1 What are MOD and DIV?
- MOD and DIV are arithmetic operators for integer division.
MODreturns the REMAINDER after division.DIVreturns the QUOTIENT (integer part) after division.- Both operators work with INTEGER values only.
- These are AS Level topics — not required at IGCSE, although some IGCSE questions do use MOD.
Example — 17 divided by 5:
// 17 divided by 5
17 DIV 5 = 3 // quotient: 5 goes into 17 three times (3 x 5 = 15)
17 MOD 5 = 2 // remainder: 17 - 15 = 2Key idea: think of primary-school division — “5 into 17 goes 3 times, remainder 2”. DIV gives the 3 (the quotient); MOD gives the 2 (the remainder). The decimal 3.4 is never produced.
What are MOD and DIV?
30.2 The DIV Operator
DIV performs integer division — it returns the whole-number quotient and discards the decimal part (it does NOT round).
Syntax: result <- dividend DIV divisor
DECLARE Result : INTEGER
Result <- 17 DIV 5
OUTPUT Result // Outputs: 3More examples:
10 DIV 3 returns 3 // 10 / 3 = 3.33..., integer part = 3
20 DIV 4 returns 5 // 20 / 4 = 5 exactly
7 DIV 2 returns 3 // 7 / 2 = 3.5, integer part = 3
15 DIV 6 returns 2 // 15 / 6 = 2.5, integer part = 2- Truncates, never rounds: 7 DIV 2 = 3 (not 4), because the .5 is discarded.
- Exact division: when there is no remainder, DIV gives the exact quotient (20 DIV 4 = 5).
- Result type: always an INTEGER — never a REAL.
Warning: DIV is not the same as ROUND or INT of a real division. DIV truncates (always rounds towards zero), so 7 DIV 2 is 3, never 4. If you need normal rounding, divide first and use ROUND().
The DIV Operator
30.3 The MOD Operator
MOD returns the remainder after integer division.
Syntax: result <- dividend MOD divisor
DECLARE Result : INTEGER
Result <- 17 MOD 5
OUTPUT Result // Outputs: 2More examples:
10 MOD 3 returns 1 // 10 = 3 x 3 + 1
20 MOD 4 returns 0 // 20 = 4 x 5 + 0, no remainder
7 MOD 2 returns 1 // 7 = 2 x 3 + 1
15 MOD 6 returns 3 // 15 = 6 x 2 + 3Key relationship: the dividend always equals the quotient times the divisor plus the remainder.
dividend = (dividend DIV divisor) * divisor + (dividend MOD divisor)
For 17 and 5: 17 = (17 DIV 5) * 5 + (17 MOD 5) = 3 * 5 + 2 = 17 ✓
- MOD 0 means exact division: 20 MOD 4 = 0 because 4 divides exactly into 20.
- Result range:
X MOD Yis always in the range 0 to Y−1. - Result type: always an INTEGER — never a REAL.
The MOD Operator
30.4 Common Uses of MOD and DIV
- Even / Odd check:
Num MOD 2 = 0means even;Num MOD 2 = 1means odd. - Extract digits:
Num MOD 10gives the last digit;Num DIV 10removes the last digit. - Time conversion: convert minutes into hours and remaining minutes.
- Currency / change: calculate the count of coins or bills of each denomination.
- Divisibility test:
A MOD B = 0means A is divisible by B.
Example — extract the digits of a 3-digit number:
DECLARE Num : INTEGER
DECLARE Hundreds, Tens, Units : INTEGER
Num <- 457
Hundreds <- Num DIV 100 // 4
Tens <- (Num MOD 100) DIV 10 // 5
Units <- Num MOD 10 // 7
OUTPUT Hundreds, Tens, Units // Outputs: 4 5 7Extract last digit
DECLARE Last : INTEGER
Last <- 457 MOD 10
OUTPUT Last // 7Remove last digit
DECLARE Rest : INTEGER
Rest <- 457 DIV 10
OUTPUT Rest // 45Rule of thumb: to extract digit at position P (counting from the right, starting at 0 for units), use (Num DIV 10^P) MOD 10. MOD 10 keeps one digit; DIV 10^P shifts right by P places first.
Common Uses of MOD and DIV
30.5 Practical Examples
Five worked examples showing MOD and DIV in typical AS Level pseudocode.
Example 1 — check if a number is even or odd:
DECLARE Num : INTEGER
INPUT Num
IF Num MOD 2 = 0 THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
ENDIFExample 2 — extract individual digits from a 3-digit number:
DECLARE Num, H, T, U : INTEGER
Num <- 457
H <- Num DIV 100
T <- (Num MOD 100) DIV 10
U <- Num MOD 10
OUTPUT H, T, U // 4 5 7Example 3 — convert minutes to hours and minutes:
DECLARE TotalMin, Hours, Mins : INTEGER
TotalMin <- 135
Hours <- TotalMin DIV 60 // 2
Mins <- TotalMin MOD 60 // 15
OUTPUT Hours, " hours ", Mins, " minutes"Example 4 — check if a number is divisible by another:
DECLARE A, B : INTEGER
INPUT A
INPUT B
IF A MOD B = 0 THEN
OUTPUT A, " is divisible by ", B
ELSE
OUTPUT A, " is NOT divisible by ", B
ENDIFExample 5 — reverse a 3-digit number using MOD and DIV:
DECLARE Num, Reversed : INTEGER
Num <- 123
Reversed <- (Num MOD 10) * 100 // 3 * 100 = 300
Reversed <- Reversed + ((Num DIV 10) MOD 10) * 10 // + 2 * 10 = 20
Reversed <- Reversed + (Num DIV 100) // + 1
OUTPUT Reversed // 321Pattern: every MOD/DIV problem is a variation on the identity dividend = quotient * divisor + remainder. Pick the divisor that isolates the digit, time unit or quantity you need (10 for digits, 60 for minutes, 24 for hours, 2 for even/odd), then combine MOD (keep) and DIV (shift) to extract it.
Practical Examples
30.6 Key Points Summary
A quick recap of everything you need to remember about MOD and DIV at AS Level.
Remember: DIV gives the quotient (how many times), MOD gives the remainder (what is left over). Both are INTEGER operations. Use them together for digit extraction, even/odd checks, divisibility tests and time conversions — the four classic AS Level use cases.