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[1000],dem1,dem2,i,n;
int main()
{
cin>>n;
dem1=0;
dem2=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
if (a[i]%2==0) dem1++;
else dem2++;
}
cout<<dem1<<" "<<dem2<<endl;
sort(a+1,a+n+1);
for (i=n; i>=1; i--) cout<<a[i]<<" ";
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[1000],t,dem,t1;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++)
if (a[i]%2==0) cout<<a[i]<<" ";
cout<<endl;
t=0;
dem=0;
for (i=1; i<=n; i++)
if (a[i]%2==0)
{
t=t+a[i];
dem++;
}
cout<<fixed<<setprecision(2)<<(t*1.0)/(dem*1.0)<<endl;
t1=0;
for (i=1; i<=n; i++)
if (a[i]%2!=0 || a[i]%3==0) t1+=a[i];
cout<<t1;
return 0;
}
uses crt;
var a:array[1..1000]of integer;
i,n,t,t1,dem,dem1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
t1:=0;
dem:=0;
dem1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
t:=t+a[i];
inc(dem);
end
else begin
t1:=t1+a[i];
inc(dem1);
end;
end;
writeln('So luong so chan la: ',dem);
writeln('Tong cac so chan la: ',t);
writeln('So luong so le la: ',dem1);
writeln('Tong cac so le la: ',t1);
readln;
end.
n = int(input("Nhập số phần tử của dãy: "))
a = [ ]
# đếm số chẵn
even_count = 0
# đếm số lẻ
odd_count = 0
for i in range(n):
a.append(int(input("Nhập phần tử thứ {0}: ".format(i+1))))
for i in a:
if i % 2 == 0:
even_count += 1
else:
odd_count += 1
print("Số lượng số chẵn trong dãy: ", even_count)
print("Số lượng số lẻ trong dãy: ", odd_count)
n = int(input("Nhập số phần tử của dãy: "))
a = [ ]
# đếm số chẵn
even_count = 0
# đếm số lẻ
odd_count = 0
for i in range(n):
a.append(int(input("Nhập phần tử thứ {0}: ".format(i+1))))
for i in a:
if i % 2 == 0:
even_count += 1
else:
odd_count += 1
print("Số lượng số chẵn trong dãy: ", even_count)
print("Số lượng số lẻ trong dãy: ", odd_count)
Đúng KO Ạ MK KO CHẮCuses crt;
var a:array[1..100]of integer;
i,n,tc,tl,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i]
else tl:=tl+a[i];
end;
writeln('Tong cac so chan la: ',tc);
writeln('Tong cac so le la: ',tl);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long x,i,n,t,dem;
int main()
{
cin>>n;
t=0;
dem=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0)
{
dem++;
t=t+x;
}
cout<<t<<" "<<dem;
return 0;
}
}
uses crt;
var a:array[1..100]of integer;
i,n,dem,dem1,dem2,j,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
writeln('Cac so le la: ');
for i:=1 to n do
if a[i] mod 2<>0 then
begin
write(a[i]:4);
inc(dem);
end;
writeln;
writeln('Co ',dem,' so le');
dem1:=0;
writeln('Cac so chan la: ');
for i:=1 to n do
if a[i] mod 2=0 then
begin
write(a[i]:4);
inc(dem1);
end;
writeln;
writeln('Co ',dem1,' so chan');
dem2:=0;
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then inc(dem2);
end;
writeln('Co ',dem2,' so nguyen to');
readln;
end.
C mk làm pascal à
câu lệnh giống nhau
thuật toán cứ chạy từ 1 đến n xét mỗi phần tử nếu a[i] mod 2 =0 thì lưu vào 1 mảng ngược lại lưu vàng mảng khác đến cuối gọi ra
uses crt;
var a:array[1..100]of integer;
i,n,tc,tl,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i]
else tl:=tl+a[i];
end;
writeln('Tong cac so chan la: ',tc);
writeln('Tong cac so le la: ',tl);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
readln;
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem1,dem2,t1,dem3,j,kt:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
dem1:=0;
dem2:=0;
t1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
dem1:=dem1+1;
t1:=t1+a[i];
end;
else dem2:=dem2+1;
end;
dem3:=0;
for i:=1 to n do
if (a[i]>1) then
begin
kt:=0;
for j:=2 to trunc(sqrt(a[i])) do
if a[i] mod j=0 then kt:=1;
if kt=0 then dem3:=dem3+1;
end;
writeln(dem1, ' ',dem2);
writeln(t1);
writeln(dem3);
readln;
end.
Program HOC24;
var a: array[1..32000] of integer;
i,n,tg,c,l: integer;
tc,tl: longint;
begin
write('Nhap N: '); readln(n);
c:=0; l:=0; tc:=0; tl:=0;
for i:=1 to n do
begin
write('Nhap so thu ',i,': '); readln(a[i];
if a[i] mod 2=0 then
begin
c:=c+1;
tc:=tc+a[i];
end;
if a[i] mod 2=1 then
begin
l:=l+1;
tl:=tl+a[i];
end;
end;
write('Day da sap xep: ');
for i:=1 to n do if a[i] mod 2=1 then write(a[i],' ');
for i:=1 to n do if a[i] mod 2=0 then write(a[i],' ');
writeln;
wirteln('Co ',l,' so le');
writeln('Co ',c,' so chan');
writeln('Tong cac so le la: ',tl);
writeln('Tong cac so chan la:', tc);
readln
end.