DIV and MOD

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

DIV and MOD

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does DIV(10, 3) return?
A 3
B 1
2. What does MOD(10, 3) return?
A 1
B 3
3. Which condition tests whether Number is even?
A MOD(Number, 2) = 0
B DIV(Number, 2) = 0
4. Which function gives the leftover part after a division?
A DIV
B MOD
5. A program splits 135 minutes into hours and minutes. Which gives the whole hours?
A MOD(135, 60)
B DIV(135, 60)

Match the Pairs

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

Left columnRight column
1DIV(10, 3) ADIV gives the quotient, not the remainder, so it cannot test for even. The test should use MOD(Number, 2) = 0.
2MOD(10, 3) BHours ← DIV(TotalMinutes, 60)
3Test whether the variable Number holds an even number CDIV gives the whole hours, not the minutes left over. The leftover minutes need MOD(TotalMinutes, 60).
4Convert TotalMinutes into whole hours (for example 135 minutes gives 2 hours) DGives the remainder when 10 is divided by 3, which is 1
5Minutes ← DIV(TotalMinutes, 60) EGives the whole-number part of 10 divided by 3, which is 3
6IF DIV(Number, 2) = 0 THEN FIF MOD(Number, 2) = 0 THEN

Definitions

DIV(a, b) and MOD(a, b)

Fill in the Blanks

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

1.
OUTPUT ___(10, 3)
2.
OUTPUT ___(10, 3)
3.
IF MOD(Number, _) = 0 THEN OUTPUT "Even" ENDIF
4.
Minutes ← 135 Hours ← DIV(Minutes, __) OUTPUT Hours
5.
Hours ← DIV(Minutes, 60) Left ← MOD(_______, 60) OUTPUT Left

Spot the Error

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

Question 1
A Number ← 10
B Part ← MOD(Number, 3)
C OUTPUT "Whole part: ", Part
Question 2
A Remainder ← DIV(10, 3)
B OUTPUT Remainder
C // Output is 1
Question 3
A INPUT Number
B // Test for an even number
C IF MOD(Number, 2) ← 0
D THEN
E OUTPUT "Even"
F ENDIF
Question 4
A INPUT TotalMinutes
B Hours ← DIV(TotalMinutes, 60)
C // Minutes left over
D Mins ← MOD(60, TotalMinutes)
E OUTPUT Hours, " h ", Mins
Question 5
A DECLARE Number : INTEGER
B Number ← 17
C Last ← MOD(Number)
D OUTPUT "Last digit: ", Last

Answer Key

DIV and MOD
Section A: Quick Questions
Q1
A — 3
Q2
A — 1
Q3
A — MOD(Number, 2) = 0
Q4
B — MOD
Q5
B — DIV(135, 60)
Section B: Match the Pairs
Q1
DIV(10, 3) → Gives the whole-number part of 10 divided by 3, which is 3
Q2
MOD(10, 3) → Gives the remainder when 10 is divided by 3, which is 1
Q3
Test whether the variable Number holds an even number → IF MOD(Number, 2) = 0 THEN
Q4
Convert TotalMinutes into whole hours (for example 135 minutes gives 2 hours) → Hours ← DIV(TotalMinutes, 60)
Q5
Minutes ← DIV(TotalMinutes, 60) → DIV gives the whole hours, not the minutes left over. The leftover minutes need MOD(TotalMinutes, 60).
Q6
IF DIV(Number, 2) = 0 THEN → DIV gives the quotient, not the remainder, so it cannot test for even. The test should use MOD(Number, 2) = 0.
Section C: Definitions
Q1
DIV(a, b) and MOD(a, b) — DIV(a, b) gives the whole-number part of a divided by b, so DIV(10, 3) is 3. MOD(a, b) gives the remainder, so MOD(10, 3) is 1. Both take integers.
Section D: Fill in the Blanks
Q1
OUTPUT DIV(10, 3)
Q2
OUTPUT MOD(10, 3)
Q3
IF MOD(Number, 2) = 0 THEN OUTPUT "Even" ENDIF
Q4
Minutes ← 135 Hours ← DIV(Minutes, 60) OUTPUT Hours
Q5
Hours ← DIV(Minutes, 60) Left ← MOD(Minutes, 60) OUTPUT Left
Section E: Spot the Error
Q1
B — The program should output the whole-number part of 10 divided by 3. MOD gives the remainder (1), not the whole part. It should be Part ← DIV(Number, 3), which gives 3.
Q2
A — The variable holds the remainder, and the output should be 1. DIV(10, 3) gives 3, the whole-number part. The remainder needs MOD(10, 3).
Q3
C — A condition compares values, so it needs the comparison operator =. The assignment arrow ← cannot be used in an IF condition. It should be IF MOD(Number, 2) = 0.
Q4
D — The arguments are the wrong way round. MOD(a, b) is the remainder of a divided by b, so the total minutes must come first. It should be Mins ← MOD(TotalMinutes, 60).
Q5
C — MOD needs two arguments: the number and the divisor. The last digit is the remainder after dividing by 10, so it should be Last ← MOD(Number, 10).