program matrixnew;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
matr:array[1..10,1..10] of integer;
mas:array[1..10] of integer;
masp:array[1..10] of integer;
masp2:array[1..10] of integer;
i,j,k,buffer,max,min:integer;
begin
writeln('Matrix');
randomize;
for i:=1 to 10 do
begin
for j:=1 to 10 do matr[i,j]:=random(100)-20;
writeln(' ');
for j:=1 to 10 do write(matr[i,j]:4);
end;
for i:=1 to 10 do
for j:=1 to 10 do if i=j then
begin
k:=k+1;
mas[k]:=matr[i,j];
end;
writeln(' ');
writeln(' ');
writeln('Main diagonal');
writeln(' ');
for i:=1 to 10 do write(mas[i]:3);
writeln('');
writeln('--------------------------------');
for i:=1 to 10 do
begin
mas[i]:=matr[i,j];
masp[i]:=matr[i,11-i];
end;
writeln(' ');
writeln(' ');
writeln('Side diagonal');
writeln(' ');
for i:=1 to 10 do write(masp[i]:3);
writeln('');
writeln('--------------------------------');
for j:=9 downto 1 do
for i:=1 to j do
if masp[i]>masp[i+1] then
begin
buffer:=masp[i];
masp[i]:=masp[i+1];
masp[i+1]:=buffer;
end;
writeln(' ');
writeln(' ');
writeln('sorted po vozrastanyu');
writeln(' ');
for i:=1 to 10 do write(masp[i]:3);
writeln('');
writeln('--------------------------------');
for j:=9 downto 1 do
for i:=1 to j do
if masp[i]<masp[i+1] then
begin
buffer:=masp[i];
masp[i]:=masp[i+1];
masp[i+1]:=buffer;
end;
writeln(' ');
writeln(' ');
writeln('sorted po ybyvanyu');
writeln(' ');
for i:=1 to 10 do write(masp[i]:3);
writeln('');
writeln('--------------------------------');
max:=masp[1];
for i:=1 to 10 do if max<masp[i] then max:=mas[i];
writeln(' ');
writeln(' ');
write('max=',max);
min:=masp[1];
for i:=1 to 10 do if max>masp[i] then max:=mas[i];
writeln(' ');
write('min=',min);
readln;
end.