大象传媒

Arithmetic operations

Computers are designed to carry out calculations. allow numerical operations to be performed on values:

Arithmetic operationOperatorExample
Addition+x = x + 5
Subtraction-x = x - 5
Multiplication*x = x * 5
Real division/x = x / 5
Integer divisionDIVx = x DIV 5
RemainderMODx = x MOD 5
Arithmetic operationAddition
Operator+
Examplex = x + 5
Arithmetic operationSubtraction
Operator-
Examplex = x - 5
Arithmetic operationMultiplication
Operator*
Examplex = x * 5
Arithmetic operationReal division
Operator/
Examplex = x / 5
Arithmetic operationInteger division
OperatorDIV
Examplex = x DIV 5
Arithmetic operationRemainder
OperatorMOD
Examplex = 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.

Example 1:

12 MOD 5

12 / 5 = 2, remainder 2

The result is 2.

Example 2:

23 MOD 6

23 / 6 = 3, remainder 5

The result is 5.