1 Sắp xếp nửa mảng trong pascal Sun Nov 13, 2011 5:41 pm
kingofthedevils
Thành viên tích cực
uses wincrt;
var tg,n,i,j,k:integer;
a:array[1..100] of integer;
begin
write('nhap n= ');
readln(n);
for i:=1 to n do
begin
write('nhap a[',i,']= ');
readln(a[i]);
end;
k:=n div 2;
for i:=1 to k-1 do
for j:=i+1 to k do
if a[i]>a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
for i:=k+1 to n do
for j:=i+1 to n do
if a[i]<a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
writeln('mang can tim la:');
for i:=1 to n do
write(a[i]:2);
readln;
end.
var tg,n,i,j,k:integer;
a:array[1..100] of integer;
begin
write('nhap n= ');
readln(n);
for i:=1 to n do
begin
write('nhap a[',i,']= ');
readln(a[i]);
end;
k:=n div 2;
for i:=1 to k-1 do
for j:=i+1 to k do
if a[i]>a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
for i:=k+1 to n do
for j:=i+1 to n do
if a[i]<a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
writeln('mang can tim la:');
for i:=1 to n do
write(a[i]:2);
readln;
end.