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
DIVdivides and throws the remainder away.17 DIV 5is3— 5 goes into 17 three whole times.
OUTPUT 17 DIV 5 // → 3
MOD: the remainder
MODgives the remainder after dividing.17 MOD 5is2. A number is even whenN MOD 2 = 0.
OUTPUT 17 MOD 5 // → 2
Watch out
DIVandMODwork on whole numbers; plain/gives a decimal.- Together they "undo" a division:
(17 DIV 5) * 5 + (17 MOD 5)=17.
Common mistakes
DIVis whole-number division;MODis the remainder.- Use brackets to control the order of arithmetic.
Now you try
- Use
+ - * /, andDIV/MOD. - Press Check answer to test it.
Output 6 times 7 (the answer is 42).
Click Run to see the output here.
Use DIV to output how many whole times 3 goes into 20 (the answer is 6).
Click Run to see the output here.
Use MOD to output the remainder when 23 is divided by 5 (the answer is 3).
Click Run to see the output here.