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[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;
}
#include <bits/stdc++.h>
using namespace std;
long long a[10000],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;
t=0;
for (i=1; i<=n; i++) if (a[i]%2==0) t+=a[i];
cout<<"Tong cac so chan la: "<<t<<endl;
sort(a+1,a+n+1);
cout<<"Day so giam dan la: ";
for (i=n; i>=1; i--) cout<<a[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,dem;
int main()
{
cin>>n;
for(i=1; i<=n; i++) cin>>a[i];
dem=0;
for (i=1; i<=n; i++) if (a[i]%10==0) dem++;
cout<<"So luong so chia het cho 2 va 5 la: "<<dem<<endl;
sort(a+1,a+n+1);
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long b[15],i,n,k,dem;
bool kt;
int main()
{
n=15;
for (i=1; i<=n; i++) cin>>b[i];
for (i=1; i<=n; i++) cout<<b[i]<<" ";
cout<<endl;
dem=0;
for (i=1; i<=n; i++) if (b[i]%2==0) dem++;
cout<<"So so chan la: "<<dem<<endl;
cin>>k;
kt=false;
for (i=1; i<=n; i++) if (b[i]==k)
{
cout<<i<<" ";
kt=true;
}
if (kt==false) cout<<"Khong co k trong day";
else cout<<endl;
sort(b+1,b+n+1);
for (i=1; i<=n; i++) cout<<b[i]<<" ";
return 0;
}
#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;
}
uses crt;
var a,b,c:array[1..100,1..100]of integer;
i,j,n,m,tam,k,tam1,i1,j1,i2,j2,tg:integer;
begin
clrscr;
write('nhap n='); readln(n);
write('nhap m='); readln(m);
for i:=1 to n do
for j:=1 to m do
begin
write('a[',i,',',j,']=');readln(a[i,j]);
end;
{--------------------gan-mang-A-cho-mang-B------------------------------}
for i:=1 to n do
for j:=1 to m do
b[i,j]:=a[i,j];
{-------------------gan-mang-A-cho-mang-C------------------------------}
for i:=1 to n do
for j:=1 to m do
c[i,j]:=a[i,j];
{---------------------------cau-a---------------------------}
for i:=1 to n do
begin
for j:=1 to m-1 do
for k:=j+1 to m do
if a[i,j]>a[i,k] then
begin
tam:=a[i,j];
a[i,j]:=a[i,k];
a[i,k]:=tam;
end;
end;
for i:=1 to n do
begin
writeln('day tang dan cua dong ',i,' la: ');
for j:=1 to m do
write(a[i,j]:4);
writeln;
end;
{---------------------------cau-b---------------------------}
for i:=1 to n-1 do
for k:=i+1 to n do
begin
for j:=1 to m do
if b[i,j]>b[k,j] then
begin
tam1:=b[i,j];
b[i,j]:=b[k,j];
b[k,j]:=tam1;
end;
end;
for j:=1 to m do
begin
writeln('day tang dan cua cot ',j,' la: ');
for i:=1 to n do
write(b[i,j]:4);
writeln;
end;
{-----------------------------------cau-c------------------------------}
writeln('ma tran tang dan zig zac cua day A la: ');
for i1:=1 to n do
for j1:=1 to m do
for i2:=1 to n do
for j2:=1 to m do
if c[i1,j1]<c[i2,j2] then
begin
tg:=c[i1,j1];
c[i1,j1]:=c[i2,j2];
c[i2,j2]:=tg;
end;
for i:=1 to n do
begin
for j:=1 to m do
write(c[i,j]:4);
writeln;
end;
readln;
end.
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.
Program HOC24;
var a: array[1..15] of integer;
tg,i,n,j: integer;
begin
n:=15;
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
for i:=1 to 7 do
for j:=i+1 to 8 do
if a[i]>a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
for i:=9 to 14 do
for j:=i+1 to 15 do
if a[i]<a[j] then
begin
tg:=a[i];
a[i]:=a[j];
a[j]:=tg;
end;
for i:=1 to n do write(a[i],' ');
readln
end.