Operators and Expressions · Cambridge syllabus 8.1 · Lesson 1 of 4
Arithmetic Operators
Arithmetic expressions in pseudocode use +, −, * for multiplication, / for division and ^ for raising to a power. Multiplication and division are done before addition and subtraction; brackets make the intended grouping clear. DIV(a, b) gives the whole-number quotient and MOD(a, b) the remainder.
By the end, you can
- Use addition.
- Use subtraction.
- Use multiplication.
- Use division.
- Use integer division where required.
- Use MOD and other supported arithmetic operations.
- Use ^ to raise a number to a power.
Arithmetic
The arithmetic operators in 0478 pseudocode are + for addition, − for subtraction, * for multiplication, / for division and ^ for raising to a power. Multiplication and division are done before addition and subtraction, as in mathematics, and brackets can change that order.
That order is a frequent source of wrong answers. An average written as Mark1 + Mark2 + Mark3 / 3 divides only Mark3; it has to be (Mark1 + Mark2 + Mark3) / 3. When in doubt, bracket it — the brackets cost nothing and make the intent explicit.
The power operator ^ raises a number to a power: 2 ^ 3 is 8, and Area ← Pi * Radius ^ 2 squares the radius before multiplying. Ordinary division gives a real result, so 7 / 2 is 3.5 even when both values are whole numbers.
Two further operations exist for whole-number work, written as functions. DIV(7, 2) gives the whole number of times 2 goes into 7, discarding the remainder: 3. MOD(7, 2) gives the remainder itself: 1. They are more useful than they look. MOD(Number, 2) = 0 tests whether a number is even, since an even number leaves no remainder, and DIV and MOD together split a total number of seconds into minutes and seconds, or pence into pounds and pence.
Two pitfalls are worth remembering: division by zero is an error that stops the program, so any divisor that could be zero must be checked first; and in some languages dividing one integer by another discards the fraction silently, so 7 / 2 gives 3 and the missing half never announces itself.
- DIV(Total, Size) gives the whole part, MOD(Total, Size) gives the remainder
- Integer division and remainder split a value into a count and what is left over — 125 seconds is DIV(125, 60) = 2 minutes and MOD(125, 60) = 5 seconds.DIV discards the fraction; MOD returns only the remainder
Worth remembering
- Operators: + − * / and ^; brackets, then multiply and divide, then add and subtract.
- DIV gives the whole part of a division; MOD gives the remainder.
- Check a divisor that could be zero before dividing by it.
Worked example
DIV(17, 5) = 3 and MOD(17, 5) = 2 because 17 = 3 × 5 + 2. 2 ^ 5 = 32.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
14 and 20 respectively.
Check your method, units and explanation against it.
Marked practice
Set 1 of 4 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.