Những câu hỏi liên quan
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;

}

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.

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.

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.

Minh Lệ
Xem chi tiết
Quoc Tran Anh Le
23 tháng 8 2023 lúc 9:20

# Nhập dãy số từ bàn phím
lst = list(map(int, input("Nhập dãy số cách nhau bởi dấu cách: ").split()))

# Sắp xếp dãy số theo thuật toán sắp xếp chọn
for i in range(len(lst)):
   min_idx = i
   for j in range(i+1, len(lst)):
       if lst[j] < lst[min_idx]:
           min_idx = j
   lst[i], lst[min_idx] = lst[min_idx], lst[i]

# In kết quả ra màn hình
print("Dãy số đã sắp xếp:", lst)

Huỳnh Tiến Thiên
Xem chi tiết
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.

Diễn Mai
Xem chi tiết
HT.Phong (9A5)
6 tháng 4 2023 lúc 18:33

Uses crt;

Var k: array[1..10] of integer;

i,j,n: byte;

t: integer;

begin clrscr;

Readln(n);

For i:=1 to n do Begin

readln(k[i]);

end;

For i:=1 to n-1 do For j:=i+1 to n do

if k[j] <=k[i] then begin

t:= k[i];

k[i]:=M[j];

k[j]:=t; end;

For i:=1 to n do Write(k[i],''); readln;

end.

Phan Thu
Xem chi tiết
bich lien
Xem chi tiết
Hồn Của Đá
29 tháng 12 2016 lúc 11:20

-so sanh hai so nhap tu ban phim:

var a,b:integer;

begin

clrscr;

write('Nhap so thu nhat:');readln(a);

write('Nhap so thu hai:');readln(b);

if a>b then writeln(a,'lon hon',b)

else writeln(a,'nho hon,'b);

if a=b then writeln(a,'bang',b);

readln;

end.

myungyeon
12 tháng 4 2017 lúc 17:12

program ctdt;
uses crt;
type mang=array[1..10]of integer;
var a,b,min,x,y,i,j,tam:integer;
t,t1:mang;
(*------------------------*)
BEGIN
clrscr;
(*cau a*)
write('nhap 2 so:');readln(a,b);
if a>b then writeln(a,' lon hon ',b);
if a=b then writeln(a,' bang ',b);
if a<b then writeln(a,' nho thua ,b);
(*cau b*)
for i:=1 to 4 do {dua 4 so vao 1 mang}
begin
write(so thu ',i,' :');readln(t[i]);
end;
min:=t[1];
for i:=2 to 4 do
if t[i]<min then min:=t[i];
writeln('so nho nhat trong bon so:',min);
(*cau c*)
write('nhap hai so x,y:');readln(x,y);
if x>y then
begin
tam:=x;
x:=y;
y:=tam;
end;
(*cau d*)
for i:=1 to 3 do {dua 3 so vao mot mang}
begin
write(' so thu ',i,': ');readln(t1[i]);
end;

for i:=1 to 3-1 do
for j:=i+1 to 3 do
if t1[j]>t1[i] then
begin
tam:=t1[j];
t1[j]:=t1[i];
t1[i]:=tam;
end;
for i:=1 to 3 do
write(t1[i]);

readln;
end.

bai nay con vai loi sai nho

ban nen chay tung cau mot va khoa cac cau con lai bang lenh {...}

le thi minh phuong
Xem chi tiết
Nguyễn Lê Phước Thịnh
21 tháng 1 2021 lúc 20:57

uses crt;

var n,i,d,x,j,tam:longint;

a:array[1..11]of integer;

st:string;

begin

clrscr;

repeat

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

until n>0;

str(n,st);

d:=length(st);

for i:=1 to d do 

  begin

val(st[i],a[i],x);

end;

for i:=1 to d-1 do 

  for j:=i+1 to d do 

if a[i]<a[j] then 

begin

tam:=a[i];

a[i]:=a[j];

a[j]:=tam;

end;

for i:=1 to d do 

  write(a[i]);

readln;

end.