MOD: remainder (8.1a)

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

MOD: remainder (8.1a)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does MOD(10, 3) return?
A 1
B 3
2. What does MOD(12, 4) return?
A 3
B 0
3. Which statement about MOD is true?
A MOD(a, b) gives the remainder after dividing a by b
B MOD(a, b) gives the whole number part of a divided by b
4. What does a MOD result of 0 tell you?
A The first number divides exactly by the second
B The first number is smaller than the second
5. Which check tests whether a number n is even?
A MOD(n, 2) = 1
B MOD(n, 2) = 0

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1MOD(10, 3) ALeft ← MOD(17, 5)
2MOD(12, 4) BThe comment is wrong: MOD gives the remainder, which is 1, not the whole-number part 3 (that is DIV).
3Check whether a whole number n is even by testing for a remainder of 0 when divided by 2 CMOD is a function, so its two values must be in brackets: MOD(10, 3).
4Store the remainder of 17 divided by 5 in a variable called Left DGives 1, because 10 divided by 3 is 3 with a remainder of 1
5Rest ← MOD 10, 3 EGives 0, because 4 divides into 12 exactly with nothing left over
6Answer ← MOD(10, 3) // gives 3 FIF MOD(n, 2) = 0 THEN

Definitions

MOD(10, 3)

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Remainder ← ___(10, 3)
2.
Rest ← MOD(10, 3) OUTPUT ____
3.
IF MOD(Number, _) = 0 THEN OUTPUT "Even" ENDIF
4.
IF MOD(Number, 2) = _ THEN OUTPUT "Odd" ENDIF
5.
IF MOD(12, 4) = _ THEN OUTPUT "Divides exactly" ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Rem : INTEGER
B DECLARE Rem : STRING
C OUTPUT Rem
Question 2
A Num ← 17
B Rem ← MOD(Num, 5)
C Rem ← Num MOD 5
Question 3
A IF Rem = 1
B Rem ← MOD(Number, 2)
C IF Rem = 0
D THEN OUTPUT "Even"
E ENDIF
Question 4
A Total ← 25
B Left ← MOD(10, Total)
C OUTPUT Left
Question 5
A DECLARE Left : INTEGER
B Minutes ← 135
C Hours ← Minutes DIV 60
D Left ← MOD(Hours, 60)
E OUTPUT Hours, Left

Answer Key

MOD: remainder (8.1a)
Section A: Quick Questions
Q1
A — 1
Q2
B — 0
Q3
A — MOD(a, b) gives the remainder after dividing a by b
Q4
A — The first number divides exactly by the second
Q5
B — MOD(n, 2) = 0
Section B: Match the Pairs
Q1
MOD(10, 3) → Gives 1, because 10 divided by 3 is 3 with a remainder of 1
Q2
MOD(12, 4) → Gives 0, because 4 divides into 12 exactly with nothing left over
Q3
Check whether a whole number n is even by testing for a remainder of 0 when divided by 2 → IF MOD(n, 2) = 0 THEN
Q4
Store the remainder of 17 divided by 5 in a variable called Left → Left ← MOD(17, 5)
Q5
Rest ← MOD 10, 3 → MOD is a function, so its two values must be in brackets: MOD(10, 3).
Q6
Answer ← MOD(10, 3) // gives 3 → The comment is wrong: MOD gives the remainder, which is 1, not the whole-number part 3 (that is DIV).
Section C: Definitions
Q1
MOD(10, 3) — MOD(a, b) gives the remainder when integer a is divided by integer b, so MOD(10, 3) is 1. A result of 0 means exact division. MOD(n, 2) is 0 for even n and 1 for odd n.
Section D: Fill in the Blanks
Q1
Remainder ← MOD(10, 3)
Q2
Rest ← MOD(10, 3) OUTPUT Rest
Q3
IF MOD(Number, 2) = 0 THEN OUTPUT "Even" ENDIF
Q4
IF MOD(Number, 2) = 1 THEN OUTPUT "Odd" ENDIF
Q5
IF MOD(12, 4) = 0 THEN OUTPUT "Divides exactly" ENDIF
Section E: Spot the Error
Q1
B — MOD(10, 3) gives the whole number 1, so Rem must be declared as INTEGER. A STRING variable cannot hold an integer remainder. It should be DECLARE Rem : INTEGER.
Q2
C — In Cambridge pseudocode MOD is a function, not an operator placed between values. It should be Rem ← MOD(Num, 5), which gives 2.
Q3
A — A remainder of 0 when dividing by 2 means the number is even. Testing for 1 would print Even for odd numbers. It should be IF Rem = 0.
Q4
B — The arguments are swapped. MOD(a, b) is the remainder of a divided by b, so the number being divided comes first. It should be MOD(Total, 10), which gives 5.
Q5
D — The minutes left over come from the remainder of the total minutes divided by 60, not from Hours. It should be Left ← MOD(Minutes, 60), which gives 15.