Arithmetic operators including DIV and MOD

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

Arithmetic operators including DIV and MOD

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is the value of 17 DIV 5?
A 3
B 2
2. What is the value of 17 MOD 5?
A 2
B 3
3. Which condition correctly tests whether Number is even?
A Number MOD 2 = 0
B Number DIV 2 = 0
4. What is the value of 20 MOD 4?
A 5
B 0
5. What is the value of 2 + 3 * 4?
A 20
B 14

Match the Pairs

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

Left columnRight column
117 DIV 5 AGives the remainder after dividing, which is 2
217 MOD 5 BGives the whole-number quotient, which is 3
3Test whether a number is even by checking that dividing by 2 leaves no remainder CDivision is worked out before addition, so only B is halved. Brackets are needed: (A + B) / 2.
4Use brackets so the addition is worked out before the multiplication DDIV gives the whole-number quotient, not the remainder. To test for even, use MOD 2 = 0.
5IF Number DIV 2 = 0 THEN ETotal <- (Price + Tax) * 3
6Average <- A + B / 2 FIF Number MOD 2 = 0 THEN

Definitions

DIV and MOD

Fill in the Blanks

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

1.
OUTPUT 17 ___ 5
2.
Remainder ← 17 ___ 5
3.
IF Number MOD 2 = _ THEN OUTPUT "Even" ENDIF
4.
Average ← (Mark1 + Mark2) _ 2
5.
Minutes ← Total DIV 60 Seconds ← Total ___ 60

Spot the Error

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

Question 1
A Items <- 17
B BoxSize <- 5
C // number of full boxes
D Boxes <- Items MOD BoxSize
E OUTPUT Boxes
Question 2
A INPUT Number
B IF Number DIV 2 = 0 THEN
C OUTPUT "Even"
D ENDIF
Question 3
A Sweets <- 23
B Left <- Sweets % 4
C OUTPUT "Left over: ", Left
Question 4
A Hours <- 135 / 60
B Mins <- 135 MOD 60
C OUTPUT Hours, Mins
Question 5
A Maths <- 80
B Average <- Maths + 70 / 2
C OUTPUT Average

Answer Key

Arithmetic operators including DIV and MOD
Section A: Quick Questions
Q1
A — 3
Q2
A — 2
Q3
A — Number MOD 2 = 0
Q4
B — 0
Q5
B — 14
Section B: Match the Pairs
Q1
17 DIV 5 → Gives the whole-number quotient, which is 3
Q2
17 MOD 5 → Gives the remainder after dividing, which is 2
Q3
Test whether a number is even by checking that dividing by 2 leaves no remainder → IF Number MOD 2 = 0 THEN
Q4
Use brackets so the addition is worked out before the multiplication → Total <- (Price + Tax) * 3
Q5
IF Number DIV 2 = 0 THEN → DIV gives the whole-number quotient, not the remainder. To test for even, use MOD 2 = 0.
Q6
Average <- A + B / 2 → Division is worked out before addition, so only B is halved. Brackets are needed: (A + B) / 2.
Section C: Definitions
Q1
DIV and MOD — Arithmetic operators beside + - * /. DIV gives the whole-number quotient (17 DIV 5 = 3). MOD gives the remainder (17 MOD 5 = 2). Number MOD 2 = 0 tests for even. Brackets set the order.
Section D: Fill in the Blanks
Q1
OUTPUT 17 DIV 5
Q2
Remainder ← 17 MOD 5
Q3
IF Number MOD 2 = 0 THEN OUTPUT "Even" ENDIF
Q4
Average ← (Mark1 + Mark2) / 2
Q5
Minutes ← Total DIV 60 Seconds ← Total MOD 60
Section E: Spot the Error
Q1
D — MOD gives the remainder (2), not the number of full boxes. The whole-number quotient needs DIV: Items DIV BoxSize gives 3.
Q2
B — DIV gives the whole-number quotient, so it cannot test for even. Use the remainder: Number MOD 2 = 0.
Q3
B — % is not a Cambridge pseudocode operator. The remainder is found with MOD: Sweets MOD 4 gives 3.
Q4
A — / gives a real number (2.25), not a whole number of hours. Whole hours need DIV: 135 DIV 60 gives 2.
Q5
B — Division is done before addition, so only 70 is halved. Brackets are needed to add first: (Maths + 70) / 2.