Implementation of the division algorithm in Pascal

<<algorithm

alg div en

program Division;
var x,  y, z: real;
begin
  write('x = ');
  readln(x);
  write('y = ');
  readln(y);
  if y=0 then
    writeln('Can not divide by 0')
  else begin
    z:=x/y;
    writeln('z = ',z);
  end;
  readln;
end.

The first line of the program can be treated as a decoration, yet it is required by the Pascal language syntax. Every Pascal program must begin with the keyword program preceding the program's name, but it contributes nothing to the algorithm's execution.

The second line is auxiliary. We know that our algorithm uses three variables to store real numbers. In Pascal, all variables must be declared before the code block begins. When declaring a variable, we must specify the data type that will be stored in it.

The third line, containing the keyword begin, corresponds to the Start block (1) of our algorithm.

Lines 4 to 7 implement the Input/Output operation (2), where the input data—the dividend and the divisor—are retrieved.

The conditional statement on line 8 is the Decision block (3) from our algorithm. The statement checks whether y is equal to 0. If the condition is met, the instruction after the keyword then is executed, which is written on line 9 (corresponding to the Input/Output block (4) in the algorithm). If the condition is not met, the instruction following the keyword else is executed; in our case, this is a compound statement enclosed in logical brackets begin and end between lines 10 and 13. First, on line 11, we calculate the quotient of x divided by y (Operation block (5)), and then, on line 12, we output the received result (Input/Output block (6)).

The readln instruction on line 14 has no relation to the execution of the division algorithm itself. It serves to pause the program until the Enter key is pressed, which prevents the program window from closing immediately.

The instruction end. on line 15 terminates the program's execution (Stop block of the algorithm (7)).