Arithmetic, DIV and MOD
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Arithmetic operators
- Pseudocode uses
+-*/for the usual maths. /gives a real answer (with a decimal point).
OUTPUT 6 + 2 // → 8
OUTPUT 6 * 2 // → 12
OUTPUT 7 / 2 // → 3.5
DIV: whole-number division
DIV(a, b)divides and throws the remainder away.DIV(17, 5)is3— 5 goes into 17 three whole times.- It is written like a function, with the two numbers in brackets — not between them.
OUTPUT DIV(17, 5) // → 3
MOD: the remainder
MOD(a, b)gives the remainder after dividing.MOD(17, 5)is2. A number is even whenMOD(N, 2) = 0.
OUTPUT MOD(17, 5) // → 2
Watch out
DIVandMODwork on whole numbers; plain/gives a decimal.- Together they "undo" a division:
DIV(17, 5) * 5 + MOD(17, 5)=17.
Common mistakes
DIV(a, b)is whole-number division;MOD(a, b)is the remainder. Both are written with brackets.- Use brackets to control the order of arithmetic.
Now you try
- Use
+ - * / ^, and the functionsDIV(a, b)/MOD(a, b). - Press Check answer to test it.
Output 6 times 7 (the answer is 42).
Click Run to see the output here.
Use DIV(20, 3) to output how many whole times 3 goes into 20 (the answer is 6).
Click Run to see the output here.
Use MOD(23, 5) to output the remainder when 23 is divided by 5 (the answer is 3).
Click Run to see the output here.