Umiestnenie súboru www.TrSek.com/zadania/ga_priem.pas{ GA_PRIEM.PAS Copyright (c) TrSek alias Zdeno Sekerak }
{ Zostavte program pre nacitanie N trojic lubovolnych cisel A,B,C, }
{ z ktorych vypocitajte aritm. a geometr. priemer. }
{ Vysledok pre jednotlive trojice tlacte v tvare tabulky }
{ }
{ Datum:04.02.2004 http://www.trsek.com }
program ga_priemer;
uses crt;
var a:array[1..100] of real;
b:array[1..100] of real;
c:array[1..100] of real;
i:integer;
n:integer;
apriem:real;
begin
ClrScr;
WriteLn('Program vypocita geometricky a aritmeticky priemer A,B,C');
Write('Zadaj pocet trojic. Maximalne 100. N=');
ReadLn(n);
{ nacita n-krat cisla a,b,c do pola }
for i:=1 to n do
begin
WriteLn;
Write('Zadaj A[',i,']='); ReadLn(a[i]);
Write('Zadaj B[',i,']='); ReadLn(b[i]);
Write('Zadaj C[',i,']='); ReadLn(c[i]);
end;
WriteLn('Vysledna tabulka je');
WriteLn;
WriteLn('Por| A | B | C | Aritmeticky | Geometricky |');
WriteLn('------------------------------------------------------------');
{ vypocita a zobrazi priemery }
for i:=1 to n do
begin
apriem := (a[i] + b[i] + c[i])/3;
Write( i:3,'|', a[i]:8:3, '|', b[i]:8:3, '|', c[i]:8:3, '|', apriem:13:3, '|' );
{ geometricky pre zaporne cisla sa neda }
if((a[i]<0) or (b[i]<0) or (c[i]<0)) Then
WriteLn(' neda sa')
else
{ geometricky priemer je 3tia odmocnina z a*b*c }
WriteLn( Exp( ln(a[i]*b[i]*c[i])/3 ):13:3);
end;