Using DIV and MOD together (8.1c)

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

Using DIV and MOD together (8.1c)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. You have 150 minutes and want the whole HOURS. Which one do you use?
A MOD(150, 60), which gives 30
B DIV(150, 60), which gives 2
2. What does MOD(150, 60) give when you split 150 minutes into hours and minutes?
A 30, the minutes left over
B 2, the whole hours
3. A price is 475 pence. Which pair splits it into pounds and pence?
A Pounds = MOD(475, 100), Pence = DIV(475, 100)
B Pounds = DIV(475, 100), Pence = MOD(475, 100)
4. Which pair of calls splits 150 into hours and minutes correctly?
A DIV(150, 60) and MOD(150, 60)
B DIV(150, 60) and MOD(60, 150)
5. How can you check that DIV and MOD have split a number a by b correctly?
A DIV(a, b) * b + MOD(a, b) gives a back
B DIV(a, b) + MOD(a, b) gives a back

Match the Pairs

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

Left columnRight column
1Hours ← DIV(150, 60) ADIV gives the whole pounds (2), not the pence left over. To get the 75 pence, use MOD(275, 100).
2Minutes ← MOD(150, 60) BDIV(a, b) * b + MOD(a, b) = a
3Check that DIV and MOD split a number correctly by rebuilding the original value a CStores the minutes left over after taking out whole hours, which is 30
4Test whether a number is even by using MOD with 2 as the divisor DStores the whole number of hours in 150 minutes, which is 2
5Pence ← DIV(275, 100) EIF MOD(Number, 2) = 0 THEN
6Minutes ← MOD(60, 150) FThe numbers are in the wrong order. The total goes first and the divisor second, so it should be MOD(150, 60).

Definitions

DIV(150, 60) and MOD(150, 60)

Fill in the Blanks

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

1.
Hours ← DIV(150, 60) Minutes ← ___(150, 60)
2.
Hours ← ___(TotalMinutes, 60) Minutes ← MOD(TotalMinutes, 60)
3.
Pounds ← DIV(Pence, 100) LeftOver ← MOD(Pence, ___)
4.
Check ← DIV(a, b) _ b + MOD(a, b)
5.
IF MOD(Number, 2) = _ THEN OUTPUT "Odd" ENDIF

Spot the Error

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

Question 1
A TotalMinutes ← 150
B Hours ← DIV(TotalMinutes, 60)
C Mins ← MOD(TotalMinutes, 60)
D OUTPUT Hours, "h ", Hours, "m"
Question 2
A Total ← 150
B Hours ← DIV(Total, 60)
C Mins ← MOD(60, Total)
D OUTPUT Hours, "h ", Mins, "m"
Question 3
A Pence ← 275
B Pounds ← DIV(Pence, 100)
C Left ← MOD(Pence, 100)
D Check ← Pounds * 10 + Left
E OUTPUT Check
Question 4
A INPUT Number
B IF DIV(Number, 2) = 0 THEN
C OUTPUT "Even"
D ELSE
E OUTPUT "Odd"
F ENDIF
Question 5
A A ← 150
B Q ← DIV(A, 60)
C R ← MOD(A, 50)
D Check ← Q * 60 + R

Answer Key

Using DIV and MOD together (8.1c)
Section A: Quick Questions
Q1
B — DIV(150, 60), which gives 2
Q2
A — 30, the minutes left over
Q3
B — Pounds = DIV(475, 100), Pence = MOD(475, 100)
Q4
A — DIV(150, 60) and MOD(150, 60)
Q5
A — DIV(a, b) * b + MOD(a, b) gives a back
Section B: Match the Pairs
Q1
Hours ← DIV(150, 60) → Stores the whole number of hours in 150 minutes, which is 2
Q2
Minutes ← MOD(150, 60) → Stores the minutes left over after taking out whole hours, which is 30
Q3
Check that DIV and MOD split a number correctly by rebuilding the original value a → DIV(a, b) * b + MOD(a, b) = a
Q4
Test whether a number is even by using MOD with 2 as the divisor → IF MOD(Number, 2) = 0 THEN
Q5
Pence ← DIV(275, 100) → DIV gives the whole pounds (2), not the pence left over. To get the 75 pence, use MOD(275, 100).
Q6
Minutes ← MOD(60, 150) → The numbers are in the wrong order. The total goes first and the divisor second, so it should be MOD(150, 60).
Section C: Definitions
Q1
DIV(150, 60) and MOD(150, 60) — Use DIV and MOD on the same two numbers to split a value. DIV gives the whole units (2 hours) and MOD gives what is left over (30 minutes). Check: DIV * b + MOD gives a back.
Section D: Fill in the Blanks
Q1
Hours ← DIV(150, 60) Minutes ← MOD(150, 60)
Q2
Hours ← DIV(TotalMinutes, 60) Minutes ← MOD(TotalMinutes, 60)
Q3
Pounds ← DIV(Pence, 100) LeftOver ← MOD(Pence, 100)
Q4
Check ← DIV(a, b) * b + MOD(a, b)
Q5
IF MOD(Number, 2) = 1 THEN OUTPUT "Odd" ENDIF
Section E: Spot the Error
Q1
D — The minutes left over are stored in Mins, but this line outputs Hours twice. It should be OUTPUT Hours, "h ", Mins, "m" so it shows 2h 30m.
Q2
C — The arguments are the wrong way round. MOD(60, Total) gives 60 MOD 150 = 60, not the leftover minutes. It should be MOD(Total, 60), which gives 30.
Q3
D — The check must multiply DIV by the same number used in DIV and MOD, which is 100. It should be Pounds * 100 + Left, which gives back 275.
Q4
B — DIV gives the whole-number quotient, not the remainder. To test for even you need the remainder, so it should be IF MOD(Number, 2) = 0 THEN.
Q5
C — DIV and MOD must use the same divisor. DIV uses 60, so MOD must also use 60. It should be R ← MOD(A, 60), otherwise Q * 60 + R will not give back A.