Features of division in Pascal
There are three division operations in the Pascal programming language:
/
- division,
div
- integer division,
mod - computing the remainder of a division.
Things to remember:
1) The operation of calculating the remainder of division (
mod) and integer division (
div
) are performed
ONLY on integers numbers.
2) The division operation (
/
) always returns a real number, and its result cannot be written to an integer variable.
Let's look at examples of performing division operations:
var i, n: integer;
x:real;
i := 7;
x := i div 4; // x = 1.0000000000000E+000, use integer division and store the result in a real variable
x := i / 4; // x = 1.750000000000E+000, use normal division
n := i div 4; // i = 1 because we use integer division and store the result in an integer variable
n := i mod 4; // n = 3, since we take the remainder of the division and write the value to an integer variable