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.
var A:
array[1..n] of integer;
i, j, n: integer;
begin
write('Nhap so phan tu cua mang: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(A[i]);
end;
for i := 1 to n - 1 do
for j := i+1 to n do
if (A[i] mod 2 = 0) and (A[j] mod 2 = 0) and (A[i] < A[j]) or (A[i] mod 2 = 1) and (A[j] mod 2 = 1) and (A[i] > A[j]) then
begin
swap(A[i], A[j]);
end;
writeln('Mang da sap xep la: ');
for i := 1 to n do
writeln(A[i]);
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;
}
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,chon;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
sort(a+1,a+n+1);
cin>>chon;
if (chon==0)
{
for (i=1; i<=n; i++) cout<<a[i]<<" ";
}
else
{
for (i=n; i>=1; 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;
}
Bài 2:
uses crt;
var x,i,n,dem:integer;
begin
clrscr;
readln(n);
dem:=0;
for i:=1 to n do
begin
readln(x);
if x mod 2=0 then inc(dem);
end;
writeln(dem);
readln;
end.