CIE IGCSE | 8.1.4F.1 Arithmetic Operators, MOD and DIV

Lesson objective

Use arithmetic expressions, apply operator precedence and parentheses, and distinguish ordinary division, integer quotient and remainder in practical algorithms.

Learn

8.1.4F.1 | ARITHMETIC OPERATORS, MOD AND DIV

01 | A PROGRAM CALCULATES WITH EXPRESSIONS

A school sells tickets, packs equipment into boxes and converts a journey duration into hours and minutes. These tasks need calculations, but they do not all need the same kind of division result.

An arithmetic operator specifies a numerical operation, such as addition or multiplication. An expression combines values, variables and operations to produce a result.

In TotalCost ← Quantity * Price, multiplication produces the cost. Assignment then stores that result in TotalCost. The operator and the assignment have separate jobs.

This lesson starts with the four basic operators, then explains the integer quotient and remainder through complete groups and leftover items.

02 | THE FOUR BASIC ARITHMETIC OPERATORS

Use the programming multiplication symbol *, not a letter x
OperatorOperationExampleResult
+Addition7 + 310
-Subtraction7 - 34
*Multiplication7 * 321
/Division7 / 23.5

The values an operator acts on are its operands. In seven plus three, seven and three are the operands.

Subtraction can produce a negative result: seven minus ten is minus three. Division can produce a fractional result even when the supplied values are whole numbers.

Choose suitable data types. A count can use INTEGER; a calculated result that may have a fractional part normally needs REAL in these examples.

03 | USE CURRENT VARIABLE VALUES

Operators can use variables rather than only written literals.

DECLARE Quantity : INTEGER
DECLARE Price : REAL
DECLARE TotalCost : REAL
Quantity ← 3
Price ← 4.50
TotalCost ← Quantity * Price
OUTPUT TotalCost

The expression reads three and four point five, multiplies them to thirteen point five, and assigns that result. It does not multiply the words Quantity and Price.

Changing Quantity later does not automatically recalculate TotalCost. Execute the calculation again if the task requires an updated cost.

For a running total, Total ← Total + Amount reads the previous total, adds the current amount and stores the new sum. Keep the right-hand calculation distinct from the destination update.

04 | MULTIPLICATION AND DIVISION COME BEFORE ADDITION

Precedence is the order in which operations within an expression are evaluated. Multiplication and division have higher precedence than addition and subtraction.

Parentheses make the intended grouping explicit
ExpressionWorkingResult
2 + 3 * 4Multiply 3 by 4, then add 214
20 - 12 / 3Divide 12 by 3, then subtract from 2016
(2 + 3) * 4Add inside parentheses, then multiply20
(20 - 12) / 4Subtract inside parentheses, then divide2

Do not simply calculate every operation from left to right while ignoring precedence. Two plus three times four is not five times four unless parentheses specify that grouping.

Cambridge recommends parentheses to make complex expressions clear. For a mean of two values, write (First + Second) / 2 rather than First + Second / 2.

Precedence within one expression differs from the execution order of separate assignment statements. Both kinds of order must be correct.

05 | ORDINARY DIVISION ANSWERS A NUMERIC QUESTION

Seventeen divided by five is three point four. That result can be useful, but it is not the number of complete five-item groups.

DECLARE Result : REAL
Result ← 17 / 5

If seventeen identical items are packed five per full box, you can fill three complete boxes and have two items left. The fractional result three point four describes the ratio, not four complete boxes.

The quotient is the result of division. For integer grouping, we need its whole part and also the remainder, which is what remains after making complete groups.

For the DIV and MOD examples below, use non-negative integer amounts and positive integer group sizes. This keeps the grouping interpretation clear without assuming another language’s rules for negative operands.

06 | DIV RETURNS THE INTEGER QUOTIENT

Cambridge defines DIV using the form DIV(Amount, GroupSize). It returns the quotient with the fractional part discarded.

DECLARE Items : INTEGER
DECLARE ItemsPerBox : INTEGER
DECLARE FullBoxes : INTEGER
Items ← 17
ItemsPerBox ← 5
FullBoxes ← DIV(Items, ItemsPerBox)

FullBoxes becomes three. Seventeen contains three complete groups of five; a fourth complete group would require twenty items.

For these non-negative values, discarding the fractional part is not rounding to the nearest whole number. DIV(19, 5) is three, even though ordinary division gives three point eight.

The two values supplied inside the parentheses are arguments. They must be INTEGER for these Cambridge operations. Use the function-style syntax shown, rather than another language’s // notation.

07 | MOD RETURNS THE REMAINDER

MOD uses the same two integer arguments but answers a different question: how much is left after the complete groups?

DECLARE LeftoverItems : INTEGER
LeftoverItems ← MOD(Items, ItemsPerBox)

With Items seventeen and ItemsPerBox five, three groups use fifteen items, leaving two. MOD(17, 5) therefore returns two.

FULL GROUP 1

5 items

FULL GROUP 2

5 items

FULL GROUP 3

5 items

LEFTOVER

2 items

MOD does not give the fractional part point four. The remainder is measured in the original items, so here it is two items.

DIV and MOD complement each other: amount equals integer quotient times group size plus remainder. Seventeen equals three times five plus two.

08 | COMPARE ALL THREE DIVISION RESULTS

Operands are non-negative integers and the divisor is positive
AmountGroup sizeOrdinary / resultDIV resultMOD result
1753.432
1953.834
205440
350.603
05000

An exact division has remainder zero. An amount smaller than the group size has zero complete groups and the whole amount left over.

For these positive divisors, the remainder is at least zero and less than the divisor. A remainder of five after dividing by five would itself form another complete group.

Zero items divided into five-item groups gives zero complete groups and zero remaining items. That is different from trying to divide by a group size of zero.

09 | EXPLORE COMPLETE GROUPS AND LEFTOVERS

Predict the quotient and remainder, then calculate. Try seventeen items in groups of five, twenty in groups of five and three in groups of five.

The illustration shows complete groups separately from leftover items. The demo uses bounded non-negative integer inputs and a positive group size.

10 | COMPLETE BOXES ARE NOT ALWAYS BOXES NEEDED

If every item must be packed, two leftover items still need a partially filled box. For seventeen items with five per box, there are three full boxes but four boxes needed altogether.

FullBoxes ← DIV(Items, ItemsPerBox)
LeftoverItems ← MOD(Items, ItemsPerBox)
BoxesNeeded ← FullBoxes
IF LeftoverItems > 0
  THEN
    BoxesNeeded ← BoxesNeeded + 1
ENDIF

Assume all named items are INTEGER with a positive ItemsPerBox. Add the extra box only if a remainder exists.

For twenty items, DIV is four and MOD is zero, so four boxes are enough. Always adding one would incorrectly request five boxes. For zero items, zero boxes are needed.

Read the scenario’s requested result: “complete groups”, “leftover items” and “containers needed for everything” are three different questions.

11 | CONVERT MINUTES TO HOURS AND REMAINING MINUTES

A journey lasts one hundred thirty-seven minutes. Each hour contains sixty minutes, so DIV counts complete hours and MOD finds minutes not included in those hours.

DECLARE TotalMinutes : INTEGER
DECLARE Hours : INTEGER
DECLARE RemainingMinutes : INTEGER
TotalMinutes ← 137
Hours ← DIV(TotalMinutes, 60)
RemainingMinutes ← MOD(TotalMinutes, 60)
OUTPUT "Hours: ", Hours
OUTPUT "Remaining minutes: ", RemainingMinutes

The outputs are two hours and seventeen remaining minutes, because one hundred thirty-seven equals two times sixty plus seventeen.

Ordinary division gives a fractional number of hours, but its fractional part is not a minute count. Use the original unit with MOD to obtain the remaining minutes.

Test exactly sixty minutes, fewer than sixty and zero to check exact division, no complete hours and empty duration.

12 | MOD HELPS TEST EVENNESS AND EXTRACT DIGITS

An even integer divides by two without a remainder. For non-negative Number, MOD(Number, 2) equal to zero identifies an even value.

IF MOD(Number, 2) = 0
  THEN
    OUTPUT "Even"
  ELSE
    OUTPUT "Odd"
ENDIF

Assume Number is declared INTEGER and assigned. Eight gives remainder zero; seven gives remainder one.

Dividing a non-negative decimal integer by ten can also separate its last digit from the earlier digits.

LastDigit ← MOD(Number, 10)
EarlierDigits ← DIV(Number, 10)

With Number one thousand two hundred thirty-four, LastDigit is four and EarlierDigits is one hundred twenty-three. This processes a numeric value; it does not preserve the formatting or leading zeros of a text identifier.

13 | CHECK THE DIVISOR BEFORE CALCULATING

The divisor is the number you divide by. Division by zero is undefined, so do not perform /, DIV or MOD with a zero divisor.

IF GroupSize > 0
  THEN
    FullGroups ← DIV(Amount, GroupSize)
    Remainder ← MOD(Amount, GroupSize)
    OUTPUT FullGroups, Remainder
  ELSE
    OUTPUT "Group size must be positive"
ENDIF

Assume INTEGER declarations and a non-negative Amount. This grouping scenario requires a positive GroupSize, so its guard also excludes negative sizes.

The check must come before the operations. Calculating first and displaying an error afterwards does not prevent the invalid division.

A clear prompt helps request a positive size, but the prompt does not enforce it without the actual check or an explicit valid-input assumption.

14 | TRACE CALCULATION AND INTERPRETATION

The interpretation step changes the container count, not DIV itself
Instruction with Items = 17 and ItemsPerBox = 5Stored resultMeaning
FullBoxes ← DIV(Items, ItemsPerBox)3Complete boxes
LeftoverItems ← MOD(Items, ItemsPerBox)2Items not in complete boxes
BoxesNeeded ← FullBoxes3Starting container count
If leftovers > 0, add one4Containers needed for all items

Trace variables after each assignment. Do not replace DIV’s three with four just because the real task needs an extra partial container; represent that additional rule explicitly.

For arithmetic tests, include an exact multiple, a non-exact multiple, an amount smaller than the divisor and a zero amount. Test invalid divisors if the requirements demand their handling.

For precedence, choose values where parentheses change the answer rather than a coincidental example giving the same result either way.

15 | COMMON MISTAKES AND CLEAR EXPLANATIONS

DIV treated as rounding: it discards the fractional part of the quotient.

MOD treated as the fractional part: it returns the remainder in original units.

Ordinary division used for an item count: distinguish a numeric ratio from complete groups.

One extra container always added: add it only when a remainder exists.

Precedence ignored: multiplication and division come before addition and subtraction; parentheses make grouping clear.

Zero divisor checked too late: guard before calculating.

A useful explanation is: “DIV finds three complete five-item boxes and MOD gives two leftover items. Because those items still need packing, the algorithm adds one partial box, resulting in four boxes needed.”

The next lesson covers relational and logical operators, which produce and combine Boolean conditions.

MATCH THE CALCULATION TO ITS RESULT

Terminology

Terminology

Arithmetic operator

A symbol or operation specifying a numerical calculation.

Expression

Values, variables and operations evaluated to produce a result.

Operand

A value on which an operator acts.

Addition

Combining numeric values using +.

Subtraction

Finding a difference using -.

Multiplication

Finding a product using *.

Division

Finding a quotient using /.

Precedence

The order in which operations within an expression are evaluated.

Parentheses

Marks specifying how an expression is grouped.

Quotient

The result of dividing one value by another.

Integer quotient

A division result with its fractional part discarded.

DIV

The Cambridge operation returning an integer quotient from integer arguments.

Remainder

The amount left after complete groups have been removed.

MOD

The Cambridge operation returning the integer-division remainder.

Divisor

The number by which another number is divided.

Argument

A value supplied to an operation such as DIV or MOD.

Exact multiple

An amount divisible by a stated positive divisor with remainder zero.

Zero-divisor guard

A check preventing division operations with a divisor of zero.

Questions

Questions

CHECK YOUR UNDERSTANDING

Select all correct choices. Each exact set earns one point.

1. Which expressions evaluate to fourteen?
2. For seventeen items in complete groups of five, which are correct?
3. What is DIV(19, 5)?
4. Which values result from MOD(20, 5) and MOD(3, 5), respectively?
5. How many boxes are needed for all seventeen items with capacity five each?
6. For twenty items with capacity five, how many boxes are needed?
7. Which calculations convert 137 minutes correctly?
8. Which safety and type statements are correct?

EXPLAIN AND COMPARE

Write your answers before revealing each sample.

1. Calculate 2 + 3 * 4 and (2 + 3) * 4, showing the order used.

2. Compare /, DIV and MOD for seventeen and five.

3. Explain why DIV(19, 5) gives three rather than four.

4. Explain why seventeen items with capacity five need four boxes even though DIV gives three.

5. Calculate hours and remaining minutes for 137 minutes and justify the operators.

6. Show how MOD tests whether a non-negative integer is even.

7. State the last digit and earlier digits obtained from the numeric value 1234 using MOD and DIV with ten.

8. Explain why a zero-divisor check must precede calculation.

BUILD IT | MINIBUSES FOR A TRIP

A minibus holds eight passengers. Receive a valid non-negative whole-number passenger count, calculate full minibuses and remaining passengers, then calculate minibuses needed to carry everyone. Output all three results. Write the complete algorithm and test twenty-three passengers, sixteen passengers and zero passengers.

Reveal one possible solution
CONSTANT SeatsPerMinibus ← 8
DECLARE Passengers : INTEGER
DECLARE FullMinibuses : INTEGER
DECLARE RemainingPassengers : INTEGER
DECLARE MinibusesNeeded : INTEGER
OUTPUT "Enter passenger count"
INPUT Passengers
FullMinibuses ← DIV(Passengers, SeatsPerMinibus)
RemainingPassengers ← MOD(Passengers, SeatsPerMinibus)
MinibusesNeeded ← FullMinibuses
IF RemainingPassengers > 0
  THEN
    MinibusesNeeded ← MinibusesNeeded + 1
ENDIF
OUTPUT "Full minibuses: ", FullMinibuses
OUTPUT "Remaining passengers: ", RemainingPassengers
OUTPUT "Minibuses needed: ", MinibusesNeeded

Twenty-three gives two full minibuses, seven remaining passengers and three minibuses needed. Sixteen gives two, zero and two. Zero gives zero for all three summaries.

The constant capacity is positive, so these assumed-valid inputs require no variable-divisor guard. The passenger count is assumed valid; a prompt alone would not validate a real input facility.

Flashcards

Flashcards

Click to flip. Select the ideas you need to revisit.

0 cards selected for revision.

    Selections are kept while this page is open.

    Workbook

    Workbook

    COMING SOON

    The workbook for 8.1.4F.1 Arithmetic Operators, MOD and DIV is coming soon. Complete the matching task and written questions in your exercise book.