MOD and DIV Gym
One division produces two answers, and DIV and MOD are the two halves of it. Drill on both, on the check that catches your own mistakes, and on knowing which of them a problem actually needs.
Get the method right under pressure
Free interactive practice on the steps that lose marks under exam pressure.
Start revising freeWhat you'll cover
One division, two answers
You already know the constructs and the conditions from the control flow module. This one is a practice session on the arithmetic, and it exists because these two operators catch people out more than anything else in the topic. Here is the idea that stops that happening. Divide seventeen by five and you get three remainder two. That is ONE division with TWO answers, and DIV and MOD are simply the two halves of it: DIV gives you the three, MOD gives you the two. Learn them as two separate rules and you will mix them up under pressure. Learn them as two halves of one division and you can always check yourself.
Words for the arithmetic
Six terms. The middle two are what the two operators actually return.
What each one gives back
Read these across rather than down. The same division is on both sides; only the half being returned changes.
Work out the whole part
Work out 17 DIV 5.
Work out the remainder
Work out 17 MOD 5.
Put it back together
You found that 17 DIV 5 is 3 and 17 MOD 5 is 2. Multiply the first answer by 5 and add the second. What do you get?
The check that never fails
What you just did is worth keeping for the exam. Take the DIV answer, multiply it by the number you divided by, add the MOD answer, and you get back the number you started with. Three times five is fifteen, plus two is seventeen. That works for every pair, every time, and it takes about four seconds. So if you are ever unsure which answer belongs to which operator, work out both and run the check. If it does not come back to the original number, you have them the wrong way round. It also tells you something useful: MOD can never be as large as the divisor, because if it were, the divisor would have fitted in one more time.
Expression to value
- 23 DIV 4
- 23 MOD 4
- 30 DIV 7
- 30 MOD 7
- 5
- 3
- 4
- 2
Which operator do you need
A program shares a number of items equally between a number of boxes and needs to know how many items will NOT fit into a full box. Which operator does it need?
- MOD, because it returns what is left after the full boxes are filled
- DIV, because it works out how the items are shared between the boxes
- Both, because you cannot find one without calculating the other first
- Neither, because sharing items equally is ordinary division
Raise it to a power
In this specification exponentiation is written with a caret. Work out 2 ^ 5.
When only the remainder will do
Select the TWO jobs that need MOD rather than DIV.
- Checking whether a number is even
- Making a counter wrap back round to zero when it reaches a limit
- Working out how many full boxes a number of items will fill
- Splitting a group of people into teams of equal size
Facts drill: DIV and MOD
Five quick calculations. Three lives.
Arithmetic in a paragraph
One division gives two answers. The whole number of times the divisor fits is returned by _____, and what is left over is returned by _____. The whole number part is called the _____ and the leftover is called the _____. A MOD answer can never be as large as the divisor, because if it were, the divisor would have fitted one more _____.
A worked pair, checked
Question: a program packs 23 items into boxes holding 4 each. How many full boxes are there, and how many items are left over? Worked answer: the number of full boxes is 23 DIV 4. Four goes into twenty-three five whole times, since five fours are twenty, so the answer is 5. The number left over is 23 MOD 4. Twenty-three take away twenty is three, so the answer is 3. Now run the check: five times four is twenty, plus three is twenty-three, which is the number we started with, so both answers are right. That check took a few seconds and it is the difference between being fairly sure and being certain. In an exam where these two operators are the thing most likely to be swapped by mistake, that is worth the time.
Which line is wrong
Three of these statements are correct. Select the ONE that has the two operators the wrong way round.
- 17 DIV 5 is 3, because five fits three whole times into seventeen.
- 17 MOD 5 is 5, because five is the number being divided by.
- 12 MOD 3 is 0, because three divides into twelve exactly.
- A MOD answer is always smaller than the divisor.
Choosing the operator
You are writing a program and have to pick the right operator at each point. Work through the decisions.
- You need to know how many complete minutes are in a number of seconds. Which operator?
- You also need the seconds left over after those whole minutes. Which operator?
- Your two answers are 4 and 90 for an input of 330 seconds. What does the check tell you?
- What does a MOD answer of 90 tell you immediately, without any arithmetic?