uses
Crt;
const
N = 3;
M = 3;
var
a: array [1..N, 1..M] of integer;
i,j,count,imax,jmax,temp,tempi,tempj: integer;
fl: boolean;
begin
ClrScr;
WriteLn('Matrix:');
imax := 1;
jmax := 1;
for i := 1 to N do
begin
for j := 1 to M do
begin
a[i, j] := Random(8) - 4;
if a[i, j] > a[imax, jmax] then
begin
imax := i;
jmax := j;
end;
Write(a[i, j]:2, ' ');
end;
WriteLn;
end;
WriteLn('Max - a[',imax, ',', jmax, '] = ', a[imax, jmax]);
repeat
count := 0;
fl := false;
for i := 1 to N do
for j := 1 to M do
begin
if not fl then
begin
tempi := i;
tempj := j;
fl := true
end
else
if a[i, j] < a[tempi, tempj] then
begin
temp := a[tempi, tempj];
a[tempi, tempj] := a[i, j];
a[i, j] := temp;
inc(count);
end;
tempi := i;
tempj := j
end;
until
count=0;
WriteLn('Result:');
for i := 1 to N do
begin
for j := 1 to M do
Write(a[i, j]:2, ' ');
WriteLn;
end;
ReadLn;
end.