Module: Arithmetic expressions


Problem

7/7

Features of division in Pascal

Theory Click to read/hide

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

Problem

1) In lines 6, 8, 10, and 12, organize the output of the value of the variable calculated in the previous line (organize the output from a new line).
2) Run the program.
3) Make sure that the program works exactly as written in the theoretical part.
4) Analyze the answers.