PASCAL


FUNCTIONS

A function is a locked sequence of instructions that allows multiple use with different parameters.
The function is declared in the following way:

   function_name (parameters and their types): function_type;

Instead of a function without parameters, it is better to use a procedure in Pascal.
We declare the procedure in the following way:

   procedure_name (parameters and their types

Przykłady:

  procedure napis(k:integer);
  var i: integer;
  begin
    for i:=0 to k do
    writeln ('xxxx');
  end;
 {MAIN}
  var n:integer;
  begin
   write('Enter the number of inscriptions');
   readln(n);
   napis(n);
 readln;
 end.
------------------
  function sum a,b:real):real;
  begin
    sum:=a+b;
  end;
 {MAIN}
  var x, y: real;
  begin
    write ('Enter the first number ');
    readln(x);
    write ('Enter the second number');
    readln(y);
  writeln ('Sum=',sum(x,y):0:4);
  readln;
  end.

The result of a function is substituted under its name. It is as if it were a variable.