Bạn chưa đăng nhập. Vui lòng đăng nhập để hỏi bài

Những câu hỏi liên quan
Hoài thịnh
Xem chi tiết
Phía sau một cô gái
27 tháng 2 2023 lúc 19:39

var A:

     array[1..n] of integer;

     i, j, n: integer;

begin

     write('Nhap so phan tu cua mang: ');

     readln(n);

     for i := 1 to n do

     begin

          write('Nhap phan tu thu ', i, ': ');

          readln(A[i]);

     end;

 

     for i := 1 to n - 1 do

         for j := i+1 to n do

            if (A[i] mod 2 = 0) and (A[j] mod 2 = 0) and (A[i] < A[j]) or (A[i] mod 2 = 1) and (A[j] mod 2 = 1) and (A[i] > A[j]) then

            begin

                swap(A[i], A[j]);

            end;

     writeln('Mang da sap xep la: ');

      for i := 1 to n do

         writeln(A[i]);

end.

 
Jhon wisk
Xem chi tiết
Kiều Vũ Linh
25 tháng 4 2023 lúc 7:31

Var a:array[1..1000] of integer;

i,m,tam:integer;

Begin

Write('m = ');readln(m);

For i:=1 to m do

Begin

Write('Nhap so thu ',i,' = ');readln(a[i]);

End;

For i:=1 to m do

If a[i] < a[i+1] then

Begin

tam:=a[i];

a[i]:=a[i+1];

a[i+1]:=tam;

End;

Write('Mang sau khi sap xep: ');

For i:=1 to m do

Write(a[i]:8);

Readln;

End.

Nguyễn Ngọc Diễm My
Xem chi tiết
Nguyễn Lê Phước Thịnh
11 tháng 4 2022 lúc 18:53

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

sort(a+1,a+n+1);

for (i=n; i>=1; i--) cout<<a[i]<<" ";

return 0;

}

Doãn Hoài Trang
Xem chi tiết
Minh Lệ
4 tháng 10 2019 lúc 11:56

program hotrotinhoc;

var a,b: array[1..8000] of integer;

c,d1: array[1..8000] of ansistring;

j,i,d,d2,n: integer;

t,t1,tg,tg1,st,s: ansistring;

begin

write('n='); readln(n);

for i:=1 to n do

begin

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

write('b[',i,']='); readln(b[i]);

end;

for i:=1 to n do if a[i] mod 2 =0 then

begin

str(a[i],t);

s:=s+t;

end

else

begin

str(a[i],t1);

st:=st+t1;

end;

for i:=1 to n do if b[i] mod 2=0 then

begin

str(b[i],t);

s:=s+t;

end

else

begin

str(b[i],t1);

st:=st+t1;

end;

d:=0;

for i:=1 to length(s) do

begin

inc(d);

c[d]:=s[i];

end;

for i:=1 to d do for j:=i to d do

if c[i]>c[j] then

begin

tg:=c[i];

c[i]:=c[j];

c[j]:=tg;

end;

for i:=1 to d do write(c[i],' ');

d2:=0;

for i:=1 to length(st) do

begin

inc(d2);

d1[d2]:=st[i];

end;

for i:=1 to d2 do

for j:=i to d2 do

if d1[i]<d1[j] then

begin

tg1:=d1[i];

d1[i]:=d1[j];

d1[j]:=tg1;

end;

for i:=1 to d2 do write(d1[i],' ');

readln

end.

nguyensonbd
Xem chi tiết
Nguyen Hung
28 tháng 4 2021 lúc 21:04

Program Tin_hoc;

Uses crt;

Var i,tam,n,chan,le,j:integer;

      a,daychan,dayle:array[1..10000] of integer;

Begin

clrscr;

Write('Nhap n: ');readln(n);

chan:=0;le:=0;

Writeln('Nhap ',n,' phan tu cua mang:');

For i:= 1 to n do 

Begin

write('A[',i,'] = ');

Readln(a[i]);

If a[i] mod 2 = 0 then 

  Begin

  inc(chan);

  daychan[chan]:=a[i];

  end

else

  Begin

  inc(le);

  dayle[le]:=a[i];

  End;

End;

For i:= 1 to chan do

  for j:= i to chan do If daychan[i]>daychan[j] then 

  Begin

  tam:=daychan[i];

  daychan[i]:=daychan[j];

  daychan[j]:=tam;

  End;

For i:= 1 to le do

  for j:= i to le do If dayle[i]<dayle[j] then 

  Begin

  tam:=dayle[i];

  dayle[i]:=dayle[j];

  dayle[j]:=tam

  End;

Writeln('Day sau khi sap xep:');

For i:= 1 to chan do write(daychan[i],'  ');

For i:= 1 to le do write(dayle[i],'  ');

Readln;

End.

k_o_t_en
Xem chi tiết
Thắng Lee
Xem chi tiết
Nguyễn Kim Trí
Xem chi tiết
Nguyễn Lê Phước Thịnh
14 tháng 3 2022 lúc 15:57

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n;

int main()

{

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

sort(a+1,a+n+1);

for (i=n; i>=1; i--) cout<<a[i]<<" ";

return 0;

}

Nguyễn Hoàng Duy
22 tháng 3 2023 lúc 22:33

program SapXepMang;
var
  N, i, j, temp: integer;
  arr: array of integer;
begin
  write('Nhap N: ');
  readln(N);
  SetLength(arr, N);
  for i := 0 to N - 1 do
  begin
    write('Nhap phan tu thu ', i + 1, ': ');
    readln(arr[i]);
  end;
  for i := 0 to N - 2 do
    for j := i + 1 to N - 1 do
      if arr[i] < arr[j] then
      begin
        temp := arr[i];
        arr[i] := arr[j];
        arr[j] := temp;
      end;
  writeln('Mang da sap xep theo thu tu giam dan: ');
  for i := 0 to N - 1 do
    write(arr[i], ' ');
  readln;
end.

 

nguyen ngoc anh
Xem chi tiết