Viết chương trình theo các yêu cầu sau:- Nhập lần lượt dãy số gồm N số nguyên dương từ bàn phím (10<=N<=20).- Chương trình thông báo kết quả ra màn hình gồm: Chuỗi ban đầu, chuỗi số được sắp xếp theo chiều tăng dần của các số chẵn và chuỗi số được sắp xếp theo chiềugiảm dần của các số lẻ.Ví dụ:-Moi ban nhap vao so N ( Với 10<=N<=20): 10-Moi ban nhap lan luot day so gom 10 so la cac so nguyen dương:+ So thu 1: 3+ So thu 2: 84+ So thu 3: 75+ So thu 4: 6+ So thu 5: 69+ So thu 6: 72+ So thu 7: 33+ So thu 8: 14+ So thu 9: 17ĐỀ CHÍNH THỨC + So thu 10: 42- Chuoi ban dau la: 3, 84, 75, 6, 69, 72, 33, 14, 17, 42- Chuoi sau khi sap xep tang dan cua cac so chan la: 6, 14, 42, 72, 84- Chuoi sau khi sap xep giam dan cua cac so le la: 75, 69, 33, 17, 3––––––––––––––––––– Hết ––––––––––––––––––––

2 câu trả lời

var a:array[0..10000] of longint;
    i,n:longint;
procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      end;
procedure sortgiam(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]>x do
            inc(i);
           while x>a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sortgiam(l,j);
         if i<r then
           sortgiam(i,r);
      end;
begin
        readln(n);
        for i:=1 to n do
        begin
                write('a[',i,']');
                read(a[i]);
        end;
        sort(1,n);
        for i:=1 to n do
                if a[i] mod 2=0 then write(a[i],' ');
                writeln;
        sortgiam(1,n);
        for i:=1 to n do
                if a[i] mod 2 <>0 then write(a[i],' ');
readln;
readln;
end.

var a:array[0..10000] of longint;

i,n,j,tg:longint;

begin

readln(n);

for i:=1 to n do

begin

write('a[',i,']');

read(a[i]);

end;

for i:=1 to n-1 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;

for i:=1 to n do

if a[i] mod 2=0 then write(a[i],' ');

writeln;

for i:=1 to n-1 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;

for i:=1 to n do

if a[i] mod 2 <>0 then

write(a[i],' ');

readln;

readln;

end.

Câu hỏi trong lớp Xem thêm