sawpsxeeps tăng dần
program bai1;
var a:array[1..5] of longint;
i,z,q,n:longint;
begin
repeat
write('N= ');
readln(n);
end;
for i:=1 to n do
begin
write('a[',i,']= ');
readln(a[i]);
end;
for i:=1 to n-1 do
for q:=i+1 to n do
if a[i]>a[q] then
begin
z:=a[i];
a[i]:=a[q];
a[q]:=z;
for i:=1 to n do write(a[i],' ');
readln
end.
Sx tăng dần:
Var i,S,i,j :integer;
A:array[1..10] of integer;
Begin
For i:= 1 to 5 do Begin
Writeln('A[',i,']=');
Readln(A[i]);
end;
For i:= 1 to n-1 do
For j:= i+1 to n do If A[i]>A[j] then
Begin
S:=A[i];
A[i]:=A[j];
A[j]:=S;
End;
Writeln (' day sau sx :');
For i:= 1 to 5 do Write (A[i]:5);
Readln;
end.
Sx giảm dần :
Var i,S,i,j :integer;
A:array[1..10] of integer;
Begin
For i:= 1 to 5 do Begin
Writeln('A[',i,']=');
Readln(A[i]);
end;
For i:= 1 to n-1 do
For j:= i+1 to n do If A[i]<A[j] then
Begin
S:=A[i];
A[i]:=A[j];
A[j]:=S;
End;
Writeln (' day sau sx :');
For i:= 1 to 5 do Write (A[i]:5);
Readln;
end.