pascal冒泡

t;begin doif d;for

pascal冒泡

代碼

var
x:array[1..100]of integer;
s,i,j,n:integer;
begin randomize;
for i:= 1 to 20 do
x[i]:=trunc(random(900))+100;
(random(n)產生0-n的隨機實數)
for s:=1 to 19 do
for j:=s+1 to 20 do
if x[s]>x[j] then begin
n:=x[s];
x[s]:=x[j];
x[j]:=n;
end;
for i:=1 to 20 do
write(x[i],' ');
writeln;
readln;
end.

或者

var
a:array[1..4]of longint;
i,j,t:longint;
begin
for i:=1 to 4 do read(a[i]);
for i:=1 to 3 do
for j:=1 to 4-i do
if a[j]<a[j+1] then
begin
t:=a[j];
a[j]:=a[j+1];
a[j+1]:=t;
end;
for i:=1 to 4 do write(a[i],' ');
end.

相關詞條

相關搜尋

熱門詞條

聯絡我們