← IGCSE Computer Science Paper 2

MOD function

Returns the remainder when a is divided by b. For example MOD(10, 3) gives 1. MOD(n, 2) = 0 means n is even.

Understanding MOD function in IGCSE Computer Science Paper 2

What it does: MOD(a, b) gives the remainder of a divided by b. 5 goes into 17 three times (15), so MOD(17, 5) returns 2. An odd number leaves a remainder of 1 when divided by 2, so MOD(Num, 2) = 1 tests for odd. MOD gives the remainder. DIV gives the whole-number part of the division (the quotient). An even number divides by 2 with no remainder, so MOD(n, 2) = 0. A result of 1 means n is odd. MOD is used as a function with two values in brackets: MOD(17, 5), which gives 2. Cambridge pseudocode does not write it in the other form.

Common mistakes: MOD(Number, 2) = 0 means there is no remainder when dividing by 2, so the number is even. The output should be "Even". A remainder of 1 when dividing by 2 means the number is odd. To test for even numbers the condition must be MOD(Number, 2) = 0.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 27–36) and word search (Modules 27–46).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does MOD(10, 3) return?
31
Matches
Answer ← MOD(10, 3) OUTPUT Answer // expects 3
↓
MOD returns the remainder, not the whole-number quotient. MOD(10, 3) is 1. Use DIV(10, 3) to get 3.
Applying
Meanings
Term
MOD(a, b)
Meaning
Returns the remainder when a is divided by b. For example MOD(10, 3) gives 1. MOD(n, 2) = 0 means n is even.
Practice
DECLARE Number : INTEGER
Testing
Gaps
Remainder ← (10, 3)
Check Answer
Spots
3IF MOD(Number, 2) = 0 THEN
4 OUTPUT "Odd"

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Tree Frog' badge — Leap of Logic, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does MOD(10, 3) return?
A. 1 ✓
B. 3
10 divided by 3 is 3 remainder 1. MOD returns the remainder, 1. The whole-number part (3) is what DIV returns.
2. Which function returns the remainder after division?
A. MOD(a, b) ✓
B. DIV(a, b)
MOD gives the remainder. DIV gives the whole-number part of the division (the quotient).
3. Which condition tests whether the integer n is even?
A. MOD(n, 2) = 0 ✓
B. MOD(n, 2) = 1
An even number divides by 2 with no remainder, so MOD(n, 2) = 0. A result of 1 means n is odd.
4. What does MOD(12, 4) return?
A. 3
B. 0 ✓
4 goes into 12 exactly 3 times with nothing left over, so the remainder is 0. The 3 would be the result of DIV(12, 4).
5. What does MOD(7, 2) return?
A. 3
B. 1 ✓
7 divided by 2 is 3 remainder 1. MOD returns the remainder, 1. An odd number always gives 1 for MOD(n, 2).

Match the Pairs

MOD(10, 3) → Gives 1, because 10 divided by 3 is 3 remainder 1
IF MOD(n, 2) = 0 THEN → Checks whether n is an even number
Find the remainder when 17 is divided by 5 → MOD(17, 5)
Test whether a whole number Num is odd → IF MOD(Num, 2) = 1 THEN
Answer ← MOD(10, 3) OUTPUT Answer // expects 3 → MOD returns the remainder, not the whole-number quotient. MOD(10, 3) is 1. Use DIV(10, 3) to get 3.
IF MOD(n, 2) = 1 THEN OUTPUT "Even" ENDIF → A remainder of 1 means n is odd, not even. To test for even, the condition should be MOD(n, 2) = 0.

Key Term

MOD(a, b)
Returns the remainder when a is divided by b. For example MOD(10, 3) gives 1. MOD(n, 2) = 0 means n is even.

Fill in the Blanks

1. Remainder ← MOD(10, 3)
Hint: Type the function name that returns the remainder of a division.
2. IF MOD(Number, 2) = 0 THEN OUTPUT "Even" ENDIF
Hint: Type the divisor that tests whether a number is even.
3. IF MOD(Number, 2) <> 0 THEN OUTPUT "Odd" ENDIF
Hint: Type the relational operator meaning 'not equal to' so the remainder shows the number is odd.
4. DECLARE Remainder : INTEGER Remainder ← MOD(10, 3)
Hint: Type the data type keyword for whole numbers, which MOD works on.
5. IF MOD(Number, 2) = 0 THEN OUTPUT "Even" ENDIF
Hint: Type the remainder value that means a number divides exactly by 2.

Spot the Error

Question 1
A DECLARE Number : INTEGER
B INPUT Number
C IF MOD(Number, 2) = 0 THEN
D OUTPUT "Odd"
E ENDIF
Line D — MOD(Number, 2) = 0 means there is no remainder when dividing by 2, so the number is even. The output should be "Even".
Question 2
A INPUT Number
B IF MOD(Number, 2) = 1 THEN
C OUTPUT "Even"
D ENDIF
Line B — A remainder of 1 when dividing by 2 means the number is odd. To test for even numbers the condition must be MOD(Number, 2) = 0.
Question 3
A DECLARE Remainder : INTEGER
B Remainder ← MOD(10 3)
C OUTPUT Remainder
Line B — MOD takes two values separated by a comma. It should be MOD(10, 3), which gives 1.
Question 4
A Total ← 0
B FOR Number ← 1 TO 10
C IF MOD(Number, 2) == 0 THEN
D Total ← Total + Number
E ENDIF
F NEXT Number
Line C — Cambridge pseudocode uses a single = to compare values. The line should be IF MOD(Number, 2) = 0 THEN.
Question 5
A INPUT Hours
B Hours ← Hours + 5
C Hours ← MOD(Hours, 24)
D OUTPUT "Hours"
Line D — Quotation marks make OUTPUT print the word Hours instead of the value stored in the variable. It should be OUTPUT Hours.

Student with a class code? Join your class →