Những câu hỏi liên quan
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)
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)
phạm tú
Xem chi tiết
Hoàng Ngọc Hân
Xem chi tiết
Nguyễn Lê Phước Thịnh
26 tháng 2 2023 lúc 16:00

#include <bits/stdc++.h>

using namespace std;

int n,A[100],i,dem=0;

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=1; i<=n; i++)

if (A[i]%2==0) dem++;

cout<<dem;

}

Bình luận (0)
Trần Văn Việt Hùng
Xem chi tiết
Nguyễn Lê Phước Thịnh
24 tháng 2 2022 lúc 13:22

#include <bits/stdc++.h>

using namespace std;

double a[100];

int i,n;

int main()

{

cin>>n;

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

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

cout<<endl;

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

swap(a[i],a[n+1-i]);

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

return 0;

}

Bình luận (1)
Đỗ Phương Thùy
Xem chi tiết
Nguyễn Lê Phước Thịnh
31 tháng 10 2021 lúc 15:18

Bài 1: 

#include <bits/stdc++.h>

using namespace std;

long long a[100],n,i,j,tam;

int main()

{

cin>>n;

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

cin>>a[i];

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

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

if (a[i]<a[j]) swap(a[i],a[j]);

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

cout<<a[i]<<" ";

return 0;

}

Bình luận (0)
nguyễn thanh hà
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)
Ngọc Linh
Xem chi tiết
Minh Lệ
7 tháng 11 2021 lúc 8:40

Input: N và dãy số nguyên a1, a2,..., aN

Ouput: dãy số sắp xếp theo thứ tự tăng dần

B1: Nhập vào n và dãy số nguyên a1, . . . ,aN;

B2: M ← N;

B3: Nếu M<2 thì in dãy đã sắp xếp rồi kết thúc;

B4. M ← M – 1; i ← 0;

B5: i ← i + 1;

B6: Nếu i > M thì quay lại bước 3;

B7. Nếu ai > ai+1 thì tráo đổi cho nhau;

B8: Quay lại bước 5; 

Bình luận (0)