Computers are designed to carry out calculations. arithmetic operatorA mathematical function that is used to perform a calculation, eg add, subtract, multiply and divide. allow numerical operations to be performed on values:
Arithmetic operation
Operator
Example
Addition
+
x = x + 5
Subtraction
-
x = x - 5
Multiplication
*
x = x * 5
Real division
/
x = x / 5
Integer division
DIV
x = x DIV 5
Remainder
MOD
x = x MOD 5
Arithmetic operation
Addition
Operator
+
Example
x = x + 5
Arithmetic operation
Subtraction
Operator
-
Example
x = x - 5
Arithmetic operation
Multiplication
Operator
*
Example
x = x * 5
Arithmetic operation
Real division
Operator
/
Example
x = x / 5
Arithmetic operation
Integer division
Operator
DIV
Example
x = x DIV 5
Arithmetic operation
Remainder
Operator
MOD
Example
x = x MOD 5
Integer division (DIV)
Integer division divides two integers and discards any remainder.
Example 1:
9 DIV 2
9 / 4 = 2 remainder 1
Discard the remainder, leaving the result as 2.
Example 2:
29 DIV 7
29 / 7 = 4 remainder 1
Discard the remainder, leaving the result as 4.
Remainder division (MOD)
Remainder division determines the remainder when one integer is divided by another.