DIV: integer division

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

DIV: integer division

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does DIV(10, 3) return?
A 3.333
B 3
2. Which expression gives the number of whole groups of 4 that can be made from 30 students?
A DIV(30, 4)
B 30 / 4
3. DIV(17, 5) returns:
A 3
B 4
4. Which statement about DIV is true?
A It rounds the result to the nearest whole number
B It discards the fractional part of the result
5. Which pseudocode correctly uses DIV?
A Groups ← DIV(25, 6)
B Groups ← 25 DIV 6.0

Match the Pairs

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

Left columnRight column
1DIV(10, 3) AReturns 3, because 3 goes into 10 three whole times and the remainder is discarded
2groups ← DIV(25, 4) BDIV discards the fractional part, so DIV(10, 3) is 3, not 3.333. Only the / operator would give 3.333.
3DIV gives the whole number of times one integer goes into another, ignoring the remainder COUTPUT DIV(17, 5)
4Dividing with / can give a decimal answer, but DIV always gives a whole number D10 / 3 gives 3.333 but DIV(10, 3) gives 3
5result ← DIV(10, 3) // result is 3.333 EDIV does not round up. 20 goes into 50 only 2 whole times, so DIV(50, 20) is 2, not 3.
6buses ← DIV(50, 20) // buses is 3 FStores 6 in groups, the number of whole groups of 4 that fit into 25

Definitions

DIV(a, b)

Fill in the Blanks

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

1.
// Displays 3 OUTPUT ___(10, 3)
2.
// 20 sweets, 4 sweets in each bag Bags ← DIV(20, _)
3.
DECLARE Groups : _______ Groups ← DIV(10, 3)
4.
// Shows 3.3333... not a whole number OUTPUT 10 _ 3
5.
Pupils ← 25 TeamSize ← 4 Teams ← DIV(Pupils, ________)

Spot the Error

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

Question 1
A DECLARE Groups : INTEGER
B Groups ← 10 / 3
C OUTPUT Groups
Question 2
A CONSTANT BoxSize ← 6
B DECLARE Boxes : INTEGER
C Boxes ← DIV(BoxSize, 50)
D OUTPUT Boxes
Question 3
A DECLARE Total, Teams : INTEGER
B Total ← 29
C Teams ← DIV(Total, 5)
D OUTPUT "Teams: " Teams
Question 4
A DECLARE Bags : INTEGER
B Bags ← DIV(47.5, 8)
C OUTPUT Bags
Question 5
A DECLARE Rows : STRING
B Rows ← DIV(25, 4)
C OUTPUT Rows

Answer Key

DIV: integer division
Section A: Quick Questions
Q1
B — 3
Q2
A — DIV(30, 4)
Q3
A — 3
Q4
B — It discards the fractional part of the result
Q5
A — Groups ← DIV(25, 6)
Section B: Match the Pairs
Q1
DIV(10, 3) → Returns 3, because 3 goes into 10 three whole times and the remainder is discarded
Q2
groups ← DIV(25, 4) → Stores 6 in groups, the number of whole groups of 4 that fit into 25
Q3
DIV gives the whole number of times one integer goes into another, ignoring the remainder → OUTPUT DIV(17, 5)
Q4
Dividing with / can give a decimal answer, but DIV always gives a whole number → 10 / 3 gives 3.333 but DIV(10, 3) gives 3
Q5
result ← DIV(10, 3) // result is 3.333 → DIV discards the fractional part, so DIV(10, 3) is 3, not 3.333. Only the / operator would give 3.333.
Q6
buses ← DIV(50, 20) // buses is 3 → DIV does not round up. 20 goes into 50 only 2 whole times, so DIV(50, 20) is 2, not 3.
Section C: Definitions
Q1
DIV(a, b) — Returns how many whole times b goes into a, discarding any remainder. DIV(10, 3) gives 3, but 10 / 3 gives 3.333. Both values are integers.
Section D: Fill in the Blanks
Q1
// Displays 3 OUTPUT DIV(10, 3)
Q2
// 20 sweets, 4 sweets in each bag Bags ← DIV(20, 4)
Q3
DECLARE Groups : INTEGER Groups ← DIV(10, 3)
Q4
// Shows 3.3333... not a whole number OUTPUT 10 / 3
Q5
Pupils ← 25 TeamSize ← 4 Teams ← DIV(Pupils, TeamSize)
Section E: Spot the Error
Q1
B — 10 / 3 gives 3.333, a REAL value, which cannot be stored in an INTEGER variable. DIV(10, 3) gives the whole number 3, so the line should be Groups ← DIV(10, 3).
Q2
C — The arguments are the wrong way round. DIV(a, b) is how many times b goes into a. Here it should be DIV(50, BoxSize), which gives 8 boxes. The broken line gives 0.
Q3
D — OUTPUT needs a comma between the items it prints. It should be OUTPUT "Teams: ", Teams, which shows 5.
Q4
B — DIV only works with integers, and 47.5 is a REAL. The line should be Bags ← DIV(47, 8), which gives 5 whole bags.
Q5
A — DIV returns a whole number, so Rows must be declared as INTEGER. A STRING variable cannot hold the result 6. It should be DECLARE Rows : INTEGER.