Type ArrInt = array[1..100] of integer;
Var a: array[1..100] of ArrInt;
b: ArrInt;
n,m,i,j,k:byte;
temp,max,min:integer;
Begin
Randomize;
{Phat sinh mang ngau nhien}
write('Nhap so cot: '); Readln(n);
write('Nhap so dong: '); Readln(m);
for i:=1 to n do
for j:=1 to m do
a[i,j]:=random(50);
{Chuyen mang 2 chieu ve mang 1 chieu}
k:=1;
for i:=1 to n do
for j:=1 to m do
begin
b[k]:=a[i,j];
inc(k);
end;
dec(k);
{Sap xep mang khong tang - Sap xep truc tiep}
for i:=1 to k-1 do
for j:=i+1 to k do
if b[j]>b[i] then
begin
temp:=b[i];
b[i]:=b[j];
b[j]:=temp;
end;
{Chuyen mang 1 chieu ve mang 2 chieu}
k:=1;
for i:=1 to n do
for j:=1 to m do
begin
a[i,j]:=b[k];
inc(k); {k:=k+1}
end;
dec(k); {k:=k-1}
{Xuat mang da sap xep}
writeln('Mang da sap xep: ');
for i:=1 to n do
begin
for j:=1 to m do
write(a[i,j]:5);
writeln;
end;
{Tim max, min}
min:=b[1]; max:=b[1];
for i:=1 to k do
begin
if b[i]>max then max:=b[i];
if b[i]<min then min:=b[i];
end;
writeln('Phan tu lon nhat la: ',max);
writeln('Phan tu nho nhat la: ',min);
readln;
End.