Napisati program sa procedurom za izračunavanje aritmeticke sredine brojeva od k do n.

Listing programa:

PROGRAM Aritmeticka_sredina;
VAR
  k, n: Integer;
  as :Real;

PROCEDURE AS_proc;
VAR
  i, br : Integer;
  s : Real;
BEGIN
  s := 0;
  br := 0;
  FOR i := k TO n DO
    BEGIN
      s := s +  i;
      br := br + 1;
    END;
  as := s / br;
END;

BEGIN       {MAIN}
  Writeln ('Artimeticka sredina ');
  Write('k  n ');
  Readln(k, n);
  AS_proc ;
  writeln('Aritmeticka sredina =  ', as);
  READLN;
END.

Ispis na ekranu:
Artimeticka sredina 
k  n 1 7
Aritmeticka sredina =   4.0000000000000000E+000

Index