Built-in Functions

AS Level

MOD & DIV (AS Level)

Master the CIE AS Level (9618) integer-division operators DIV (quotient) and MOD (remainder) — including the canonical identity, even/odd checks, digit extraction, divisibility tests and time conversion.

30.1 What are MOD and DIV?

  • MOD and DIV are arithmetic operators for integer division.
  • MOD returns the REMAINDER after division.
  • DIV returns 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 = 2

Key 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.

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: 3

More 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().

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: 2

More 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 + 3

Key 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 Y is always in the range 0 to Y−1.
  • Result type: always an INTEGER — never a REAL.

30.4 Common Uses of MOD and DIV

  • Even / Odd check: Num MOD 2 = 0 means even; Num MOD 2 = 1 means odd.
  • Extract digits: Num MOD 10 gives the last digit; Num DIV 10 removes 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 = 0 means 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 7

Extract last digit

DECLARE Last : INTEGER
Last <- 457 MOD 10
OUTPUT Last   // 7

Remove last digit

DECLARE Rest : INTEGER
Rest <- 457 DIV 10
OUTPUT Rest   // 45

Rule 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.

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"
ENDIF

Example 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 7

Example 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
ENDIF

Example 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   // 321

Pattern: 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.

30.6 Key Points Summary

A quick recap of everything you need to remember about MOD and DIV at AS Level.

DIV returns the QUOTIENT (integer part) after division.
MOD returns the REMAINDER after integer division.
Both MOD and DIV work with INTEGER values only.
DIV discards the decimal part — it does NOT round.
dividend = (dividend DIV divisor) * divisor + (dividend MOD divisor).
Even check: Num MOD 2 = 0.
Odd check: Num MOD 2 = 1.
Last digit: Num MOD 10.
Remove last digit: Num DIV 10.
Divisibility test: A MOD B = 0 means A is divisible by B.

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.

Question Bank

Answer all questions, then press Submit Quiz to see your score.

0/12 answered

Question 1Multiple Choice

What is the value of 23 DIV 5?

Question 2True / False

23 MOD 5 returns 3.

Question 3Multiple Choice

DECLARE Result : INTEGER
Result <- 100 DIV 7
OUTPUT Result

Question 4Multiple Choice

What is the value of 100 MOD 7?

Question 5True / False

DIV rounds the result of division to the nearest integer.

Question 6Multiple Choice

DECLARE Num : INTEGER
Num <- 7
IF Num MOD 2 = 0 THEN
  OUTPUT "Even"
ELSE
  OUTPUT "Odd"
ENDIF

Question 7Multiple Choice

Which expression extracts the TENS digit of a 2-digit integer N (for example, the 4 in 47)?

Question 8True / False

The expression (17 DIV 5) * 5 + (17 MOD 5) evaluates to 17.

Question 9Multiple Choice

DECLARE Num : INTEGER
DECLARE Hundreds, Tens, Units : INTEGER
Num <- 932
Hundreds <- Num DIV 100
Tens <- (Num MOD 100) DIV 10
Units <- Num MOD 10
OUTPUT "Hundreds=", Hundreds, " Tens=", Tens, " Units=", Units

Question 10Multiple Choice

DECLARE TotalMin : INTEGER
DECLARE Hours, Mins : INTEGER
TotalMin <- 200
Hours <- TotalMin DIV 60
Mins <- TotalMin MOD 60
OUTPUT Hours, " hours ", Mins, " minutes"

Question 11True / False

50 MOD 5 = 0 means that 50 is divisible by 5.

Question 12Multiple Choice

DECLARE Num : INTEGER
DECLARE Reversed : INTEGER
Num <- 45
Reversed <- (Num MOD 10) * 10
Reversed <- Reversed + (Num DIV 10)
OUTPUT Reversed

Answer all 12 questions to enable submission.