Calculate harmonics, geometrics, arithmetics and quadratics average
Delphi & Pascal (česká wiki)
Category: Homework in Pascal
Program: Priemery.pas
File exe: Priemery.exe
Program: Priemery.pas
File exe: Priemery.exe
Calculate harmonics, geometrics, arithmetics and quadratics average.
{ PRIEMERY.PAS Copyright (c) TrSek alias Zdeno Sekerak } { Zistite harmonicky, geometricky, aritmeticky a kvadraticky } { priemer danych n kladnych cisel. } { } { Datum:23.05.2004 http://www.trsek.com } program priemery; var poc:integer; p1,p2,p3,p4: real; i:integer; x:real; begin WriteLn('Vypocitam harmonicky, geometricky, aritmeticky a kvadraticky priemer.'); Write('Zadaj kolko bude cisel:'); ReadLn(poc); { znulujeme } p1:=0; p2:=1; p3:=0; p4:=0; for i:=1 to poc do begin Write('x[',i,']='); ReadLn(x); if(x<=0) then WriteLn('Iba kladnych cisel'); p1 := p1+(1/x); p2 := p2*x; p3 := p3+x; p4 := p4+(x*x) end; p1 := poc/p1; p2 := Exp(ln(p2)/poc); p3 := p3/poc; p4 := sqrt(p4/poc); WriteLn('Harmonicky priemer je:', p1:1:3 ); WriteLn('Geometrciky priemer je:', p2:1:3 ); WriteLn('Aritmeticky priemer je:', p3:1:3 ); WriteLn('Kvadraticky priemer je:', p4:1:3 ); ReadLn; end.