Uses crt;
Const
nmax = 100;
mma = 100;
Var
a: array[1..nmax,1..mmax] of integer;
i,j,n,m,min,max: byte;
buf: integer;
FileName: string[20];
f: text;
Begin
Clrscr;
Randomize;
Repeat
Write('Введите количество строк (до ',nmax,') : ');
Readln(n)
Until n in [1..nmax];
Repeat
Write('Введите количество столбцов (до ',mmax,') : ');
Readln(m)
Until m in [1..mmax];
Writeln('Исходная матрица');
For i:=1 to n do
begin
For j:=1 to m do
begin
a[i,j]:=random(61)-30;
Write(a[i,j]:4)
end;
Writeln
end;
Writeln;
For i:=1 to n do
begin
max:=1;
min:=1;
For j:=2 to m do
If a[i,j]>a[i,max] then max:=j
else if a[i,j]<a[i,min] then min:=j;
buf:=a[i,max];
a[i,max]:=a[i,min];
a[i,min]:=buf;
end;
Write('имя файла: ');
Readln(FileName);
Assign(f,filename);
Rewrite(f);
For i:=1 to n do
begin
For j:=1 to m do write(f,a[i,j]:4);
Writeln(f);
end;
end.