Những câu hỏi liên quan
Huy Phạm
Xem chi tiết
Kiều Vũ Linh
3 tháng 5 2023 lúc 6:12

1)

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

i,n,t:integer;

Begin

Write('n = ');readln(n);

For i:=1 to n do

Begin

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

End;

For i:=1 to n do

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

Begin

t:=a[i];

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

a[i+1]:=t;

End;

Write('Sap xep tang dan ');

For i:=1 to n do write(a[i]:8);

Readln

End.

Bình luận (0)
Kiều Vũ Linh
3 tháng 5 2023 lúc 6:13

2)

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

i,n,t:integer;

Begin

Write('n = ');readln(n);

For i:=1 to n do

Begin

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

End;

For i:=1 to n do

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

Begin

t:=a[i];

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

a[i+1]:=t;

End;

Write('Sap xep giam dan ');

For i:=1 to n do write(a[i]:8);

Readln

End.

Bình luận (0)
khonopro
Xem chi tiết
Nguyễn Lê Phước Thịnh
9 tháng 3 2023 lúc 15:01

#include <bits/stdc++.h>

using namespace std;

int A[1000],n,i;

int main()

{

cin>>n;

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

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

for (int i=1; i<=n; i++)

cout<<A[i]<<" ";

cout<<endl;

for (int i=2; i<=n; i++)

cout<<A[i]-A[i-1]<<endl;

return 0;

}

Bình luận (1)
Văn Công Sỹ
Xem chi tiết
Văn Công Sỹ
25 tháng 4 2021 lúc 10:28

Làm giúp bài này nhé

 

Bình luận (0)
Bùi Anh Tuấn
25 tháng 4 2021 lúc 19:41

Bình luận (0)
Nguyễn Lê Phước Thịnh
25 tháng 4 2021 lúc 22:19

uses crt;

var a:array[1..100]of integer;

i,n,min,tam,j:integer;

begin

clrscr;

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

for i:=1 to n do

begin

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

end;

min:=a[1];

for i:=1 to n do 

  if min>a[i] then min:=a[i];

writeln('Gia tri nho nhat la: ',min);

for i:=1 to n-1 do 

  for j:=i+1 to n do 

if a[i]<a[j] then 

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

for i:=1 to n do write(a[i]:4);

readln;

end.

Bình luận (0)
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.

Bình luận (0)
Panda
Xem chi tiết
ádfg
Xem chi tiết
Nguyễn Lê Phước Thịnh
10 tháng 12 2021 lúc 23:11

#include <bits/stdc++.h>

using namespace std;

long long a[100],b[100],c[100],n,i,dem1,dem2;

int main()

{

cin>>n;

for (i=1; i<=n; i++)

cin>>a[i];

dem1=0;

dem2=0;

for (i=1; i<=n; i++)

{

if (a[i]%2==0) 

{

dem1++;

b[dem1]=a[i];

}

else 

{

dem2=0;

c[dem2]=a[i];

}

}

sort(b+1,b+dem1+1);

sort(c+1,c+dem2+1);

for (i=1; i<=dem1; i++)

cout<<b[i]<<" ";

for (i=dem2; i>=1; i--)

cout<<c[i]<<" ";

return 0;

}

Bình luận (0)
bui pham phuong Uyen
Xem chi tiết
Nguyễn Lê Phước Thịnh
27 tháng 1 2021 lúc 13:15

Bài 1: 

uses crt;

var a:array[1..100]of integer;

i,n,kt,max,x,j,tam:integer;

begin

clrscr;

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

for i:=1 to n do 

  begin

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

end;

writeln('Mang ban vua nhap la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

for i:=1 to n-1 do 

  for j:=i+1 to n do 

if a[i]>a[j] then 

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

writeln('Day tang dan la: ');

for i:=1 to n do 

  write(a[i]:4);

writeln;

write('Nhap x='); readln(x);

max:=0;

kt:=0;

for i:=1 to n do 

  if (a[i] mod 2=0) and (a[i]<=x) then 

   begin

  if max<a[i] then max:=a[i];

kt:=1;

end;

if kt=0 then writeln('Trong day khong co so le')

else writeln('So chan lon nhat khong vuot qua ',x,' la: ',max);

readln;

end.

Bình luận (0)
Long Phan
Xem chi tiết
Asuna
Xem chi tiết

Dưới đây là mã chương trình Pascal để sắp xếp dãy số theo yêu cầu đã cho:

```pascal
program sorting;

const
MAX_N = 1000;

var
N, i, j, temp: integer;
arr: array[1…MAX_N] of integer;
oddArr, evenArr: array[1…MAX_N] of integer;
oddCount, evenCount: integer;
inputFile, outputFile: text;

begin
// Mở file input và đọc dữ liệu
assign(inputFile, 'sorting.inp');
reset(inputFile);
readln(inputFile, N);
for i := 1 to N do
read(inputFile, arr[i]);
close(inputFile);

// Sắp xếp mảng theo yêu cầu
oddCount := 0;
evenCount := 0;
for i := 1 to N do
begin
if arr[i] mod 2 = 1 then
begin
oddCount := oddCount + 1;
oddArr[oddCount] := arr[i];
end
else
begin
evenCount := evenCount + 1;
evenArr[evenCount] := arr[i];
end;
end;

// Sắp xếp mảng số lẻ tăng dần
for i := 1 to oddCount - 1 do
for j := i + 1 to oddCount do
if oddArr[i] > oddArr[j] then
begin
temp := oddArr[i];
oddArr[i] := oddArr[j];
oddArr[j] := temp;
end;

// Sắp xếp mảng số chẵn giảm dần
for i := 1 to evenCount - 1 do
for j := i + 1 to evenCount do
if evenArr[i] < evenArr[j] then
begin
temp := evenArr[i];
evenArr[i] := evenArr[j];
evenArr[j] := temp;
end;

// Mở file output và ghi kết quả
assign(outputFile, 'sorting.out');
rewrite(outputFile);
for i := 1 to oddCount do
write(outputFile, oddArr[i], ' ');
writeln(outputFile);
for i := 1 to evenCount do
write(outputFile, evenArr[i], ' ');
close(outputFile);
end.
```

Bạn có thể sao chép mã chương trình trên vào một tệp tin có tên `sorting.pas`, sau đó tạo một tệp tin `sorting.inp` và nhập dữ liệu theo định dạng đã cho. Chạy chương trình và kết quả sẽ được ghi vào tệp tin `sorting.out`.

Bình luận (0)
Phạm Dương Phúc Khang
21 tháng 1 lúc 22:55

var i,n:longint; a:array[1..1000] of longint;

begin

readln(n);

for i:=1 to n do read(a[i]);

for i:=1 to n do

     if a[i] mod 2=0 then 

         begin

              inc(k);

              b[k]:=a[i];

         end

else

begin

inc(t);

c[t]:=a[i];

end;

for i:=1 to k-1 do

for j:=i+1 to k do

if b[i]<b[j] then

begin

d:=b[i];

b[i]:=b[j];

b[j]:=d;

end;

for i:=1 to  t-1 do

for j:=i+1 to t do

if c[i]>c[j] then

begin

d:=c[i];

c[i]:=c[j];

c[j]:=d;

end;

for i:=1 to k do write(b[i],' ');

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

end.

Bình luận (0)