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.
#include <bits/stdc++.h>
using namespace std;
long long a[8],n,i,j;
int main()
{
n=8;
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;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],n,i,tam,j;
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à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;
}
#include <bits/stdc++.h>
using namespace std;
long long b[10],i,j,n;
int main()
{
n=10;
for (i=1; i<=n; i++)
cin>>b[i];
for (i=1; i<=n-1; i++)
for (j=i+1;j<=n;j++)
if (b[i]<=b[j]) swap(b[i],b[j]);
for (i=1; i<=n; i++)
cout<<b[i]<<" ";
return 0;
}
Tham khảo:
program im_14424;
uses crt;
var A:array [1..1000] of integer;
i,j,n,tg:integer;
begin clrscr;
write('Nhap so phan tu n: '); readln(n);
for i:=1 to n do
begin
write('Nhap so thu ',i,': ');
read(A[i]);
end;
for i:=1 to n-1 do
for j:=i+1 to n do
if A[i]>A[j] then
begin
tg:=A[i];
A[i]:=A[j];
A[j]:=tg;
end;
writeln('Day so sap xep theo thu tu tang dan la: ');
for i:=1 to n do
write(A[i]:3);
readln;
end.
Code bằng C++
#include <bits/stdc++.h>
using namespace std;
long long a[1000000],i,j,n;
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;
}