Dze je subor www.TrSek.com/zadania/minmat.pas{ MINMAT.PAS Copyright (c) TrSek alias Zdeno Sekerak }
{ Medzi riadkami danej celociselnej matice, najdite riadok }
{ s minimalnym suctom absolutnych hodnot. }
{ }
{ Datum:23.05.2004 http://www.trsek.com }
program min_matica;
const MAX=100;
var m:array[1..MAX,1..MAX] of integer;
max_x,max_y:integer; { pocet stlpcov, riadkov }
x,y:integer; { pre cykly }
pom:integer;
min:integer; { minimalna najdena hodnota }
riad:integer; { riadok minimalnej hodnoty }
begin
WriteLn('Ziskanie riadku matice s minimalnym suctom absolutnych hodnot.');
Write('Zadaj pocet stlpcov (max=',MAX,'):'); ReadLn(max_x);
Write('Zadaj pocet riadkov (max=',MAX,'):'); ReadLn(max_y);
{ najprv zadanie hodnot }
WriteLn('Zadaj jednotlive prvky matice');
for y:=1 to max_y do
for x:=1 to max_x do
begin
Write('m[',x,',',y,']=');
ReadLn(m[x,y]);
end;
{ inicializacia }
riad:=0;
min:=0;
{ v cykle zistujeme }
for y:=1 to max_y do
begin
pom:=0; { znulujeme }
for x:=1 to max_x do
pom:=pom+abs(m[x,y]);
if((riad=0) or (pom<min))then
begin
riad:=y;
min:=pom;
end;
end;
WriteLn('Riadok s minimalnym suctom absolutnych hodnot je ',riad);
ReadLn;
end.