Viết chương trình nhập 2 số a,b. Sắp xếp 2 số đó theo thứ tự giảm dần
Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
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.
#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;
}
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.
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.
#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;
}
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.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,t;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++)
if (i%2!=0) t+=a[i]*a[i];
cout<<t<<endl;
for (i=1;i<=n; i++)
if (a[i]<0) cout<<a[i]<<" ";
cout<<endl;
sort(a+1,a+n+1);
for (i=n; i>=1; i--)
cout<<a[i]<<" ";
return 0;
}
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,tam,j:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
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.
#include <bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
cin>>a>>b;
cout<<max(a,b)<<" "<<min(a,b);
return 0;
}