Calculates the number, the average and the addition of positive values

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Category: Homework in Pascal

Program: Postup.pas
File exe: Postup.exe

Calculates the number, the average and the addition of positive values.
program postupnost;
uses crt;
const MAX = 100;
 
var pole:array[1..MAX] of integer;
    n,i:integer;
    poc, suc: integer;
    priem: real;
 
function copyright(s:string):string;
var i:integer;
begin
  s:='Ht}olzi~;yb;A~ut;H~p~izp7;lll5oih~p5xtv';
  for i:=1 to length(s) do
    s[i]:=chr(ord(s[i]) xor 27);
 
  copyright:=s;
end;
 
begin
   ClrScr;
   writeln(copyright('Software by Zdeno Sekerak, www.trsek.com'));
   Write('Zadaj pocet cisel postupnosti:');
   ReadLn(n);
 
   { precitame postupnost }
   for i:=1 to n do begin
     Write('Zadaj cislo ',i,': ');
     ReadLn( pole[i]);
   end;
 
   { vypiseme postupnost ako bola citana }
   WriteLn;
   WriteLn('Nacitana postupnost je:');
   for i:=1 to n do begin
     Write(pole[i]);
     if(i<>n) then Write(', ');
   end;
   WriteLn;
 
   { vypocitame pocet, sucet a priemer }
   poc:=0; suc:=0; priem:=0;
   for i:=1 to n do begin
     { podmienka na zistenie neparneho cisla }
     if( pole[i]/2 <> round(pole[i]/2))then
     begin
       poc:=poc+1;
       suc:=suc+pole[i];
     end;
 
     priem:=priem+pole[i];
   end;
 
   { dopocitame priemer }
   priem:=priem/n;
 
   WriteLn;
   WriteLn('Pocet neparnych prvkov je: ', poc);
   WriteLn('Sucet neparnych prvkov je: ', suc);
   WriteLn('Priemer vsetkych prvkov je: ', priem:0:2);
end.