Uses crt;
Type MyType = integer;
Var
n,m,i,j,xi,xj: byte;
a: array[1..100,1..100] of MyType;
Procedure Stroka(i,i1: byte);
var
j: byte;
buf: MyType;
begin
For j:=1 to m do
begin
buf:=a[i,j];
a[i,j]:=a[i1,j];
a[i1,j]:=buf
end
end;
Procedure Stolb(j,j1: byte);
var
i: byte;
buf: MyType;
begin
For i:=1 to n do
begin
buf:=a[i,j];
a[i,j]:=a[i,j1];
a[i,j1]:=buf
end
end;
Begin
Clrscr;
Write('n=');
Readln(n);
Write('m=');
Readln(m);
Randomize;
For i:=1 to n do
begin
For j:=1 to m do
begin
a[i,j]:=random(21)-5;
Write(a[i,j]:4);
end;
Writeln;
end;
Writeln;
xi:=1; xj:=1;
For i:=1 to n do
For j:=1 to m do
If a[i,j] < a[xi,xj] then
begin
xi:=i;
xj:=j
end;
While xi > 1 do
begin
Stroka(xi,xi-1);
Dec(xi)
end;
While xj < n do
begin
Stolb(xj,xj+1);
Inc(xj)
end;
For i:=1 to n do
begin
For j:=1 to m do write(a[i,j]:4);
Writeln
end;
End.
Type MyType = integer;
Var
n,m,i,j,xi,xj: byte;
a: array[1..100,1..100] of MyType;
Procedure Stroka(i,i1: byte);
var
j: byte;
buf: MyType;
begin
For j:=1 to m do
begin
buf:=a[i,j];
a[i,j]:=a[i1,j];
a[i1,j]:=buf
end
end;
Procedure Stolb(j,j1: byte);
var
i: byte;
buf: MyType;
begin
For i:=1 to n do
begin
buf:=a[i,j];
a[i,j]:=a[i,j1];
a[i,j1]:=buf
end
end;
Begin
Clrscr;
Write('n=');
Readln(n);
Write('m=');
Readln(m);
Randomize;
For i:=1 to n do
begin
For j:=1 to m do
begin
a[i,j]:=random(21)-5;
Write(a[i,j]:4);
end;
Writeln;
end;
Writeln;
xi:=1; xj:=1;
For i:=1 to n do
For j:=1 to m do
If a[i,j] < a[xi,xj] then
begin
xi:=i;
xj:=j
end;
While xi > 1 do
begin
Stroka(xi,xi-1);
Dec(xi)
end;
While xj < n do
begin
Stolb(xj,xj+1);
Inc(xj)
end;
For i:=1 to n do
begin
For j:=1 to m do write(a[i,j]:4);
Writeln
end;
End.