For i:=1 to n do
begin
a[i]:=random (20);
write(a[i],' ')
end;
for j:=n-1 downto 1 do
for i:=1 to j do
if a[i]>a[i+1] then
begin
x:=a[i];
a[i]:=a[i+1];
a[i+1]:=x
end;
writeln;
for i:=1 to n do write(a[i],' ')
В программе:
var
i,j,n,x:integer;
a:array [1..100] of integer;
begin
readln (n);
for i:=1 to n do
begin
a[i]:=random (20);
write(a[i],' ')
end;
for j:=n-1 downto 1 do
for i:=1 to j do
if a[i]>a[i+1] then
begin
x:=a[i];
a[i]:=a[i+1];
a[i+1]:=x
end;
writeln;
for i:=1 to n do write(a[i],' ')
end.
Пример:
10
3 0 19 18 5 1 4 7 16 8
0 1 3 4 5 7 8 16 18 19