viết chương trình python sắp xếp danh sách theo thứ tự tăng dần gồm n phần tử với n nhập từ bàn phím
mô tả thuật toán và viết chương trình sắp xếp dãy số A gồm N phần tử(N được nhập từ bàn phím) sắp xếp theo thứ tự tăng dần
(pascal)
Sử dụng python mới
Bài 2: Nhập mảng A gồm n phần tử (n nhập vào từ bàn phím). In ra màn hình:
- Mảng vừa nhập;
- Sắp xếp mảng vừa nhập theo thứ tự tăng dần
- In ra mảng đã đƣợc sắp
Viết chương trình nhập vào 1 mảng số nguyên dương gồm có n phần tử (0 < n < 50) từ bàn phím. Sắp xếp lại mảng vừa nhập theo thứ tự giảm dần và lưu mảng sau khi đã sắp xếp vào tệp nhị phân.
Mọi ng giúp e với ạ
viết chương trình thực hiện các yêu cầu sau:nhập vào một mảng gồm n phần tử,hiển thị danh sách các phần tử trong mảngvừa nhập,sắp xếp danh sách các phần tử lẽ trong mảng theo thứ tự giảm dần,hiển thị danh sách các phần tử trong mảng vừa được sắp xếp
Viết một chương trình thực hiện các công việc sau:
- Nhập từ bàn phím 1 dãy A gồm N số nguyên (với N được nhập từ bàn phím).
- Sắp xếp dãy số đó theo chiều giảm dần.
- In ra mà hình tất cả các phần tử chẵn
- Tìm và đưa ra chỉ số của phần tử có gía trị = K (với K là số nguyên và được nhập từ bàn phím).
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[1000];
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;
}
Viết chương trình nhập một dãy số gồm n số tự nhiên (n nhập từ bàn phím), sắp xếp chúng theo thứ tự tăng dần và in ra màn hình :
a) Dãy đã sắp
b) Các khoảng cách của hai số liền kề (hiệu của hai số đó )
#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;
}
1.Viết chương trình nhập vào một dãy số gồm n phần tử.Sắp xếp dãy số theo thứ tự tăng dần sau đó in ra màn hình dãy số đã sắp xếp. 2.Viết chương trình nhập vào một dãy số gồm n phần tử. Sắp xếp dãy số theo thứ tự giảm dần sau đó in ra màn hình dãy số đã sắp xếp.(cứu mk với mai thi r ạ🥲
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.
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ài 1:Viết chương trình nhập vào một mảng số nguyên gồm n phần tử(n<100) nhập từ bàn phím thực hiện các công việc sau:
a)In ra màn hình các phần tử của mảng vừa nhập.
b) Sắp xếp dãy số nguyên theo thứ tự tăng dần.
c) Nhập số nguyên x bất kì.Tính số chắn lớn nhất không được vượt quá x.
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.
Viết chương trình hoàn thành các công việc sau:- Nhập một dãy số có N phần tử (0<N<=100). Yêu cầu :- Sắp xếp dãy số vừa nhập đó theo thứ tự tăng dần.- Tìm một số x nhập từ bàn phím, kiểm tra số x đó có trong dãy số vừa nhập không. Nếu có cho biết vị tríđầu tiên của số x trong dãy, ngược lại thì báo không có số x trong dãy số.- Xóa một số x nhập từ bàn phím, nếu có thì xóa số x đầu tiên trong dãy, ngược lại thì báo không có số xtrong dãy số.- Sửa một số tại vị trí thứ k trong dãy. Nhập vào một vị trí k cần sửa, chương trình cho biết giá trị phần tửở vị trí k đó và yêu cầu nhập giá trị cần sửa.- Chèn một số vào vị trí k, nhập từ bàn phím vị trí k và giá trị cần chèn vào dãy số.- In dãy số hiện hành ra màn hình.- Thoát khỏi chương trình
In ra màn hìnhHAY CHON MOT TRONG CAC SO SAU:1.Nhap day so :2.Sap xep day so :3.Tim mot so :4.Xoa mot so :5.Sua mot so:6.Chen mot so :7.In day so:8.Thoat chuong trinh.