Nhập vào dãy số nguyên gồm n phần tử,đếm xem trong dãy có bao nhiêu số chẵ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.
Program HOC24;
var d,i,n: integer;
a: array[1..1000] of integer;
t: longint;
function nt(x: longint): boolean;
var j: longint;
begin
nt:=true;
if (x=2) or (x=3) then exit;
nt:=false;
if (x=1) or (x mod 2=0) or (x mod 3=0) then exit;
j:=5;
while j<=trunc(sqrt(x)) do
begin
if (x mod j=0) or (x mod (j+2)=0) then exit;
j:=j+6;
end;
nt:=true;
end;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
d:=0; t:=0;
for i:=1 to n do
if nt(a[i]) then
begin
d:=d+1;
t:=t+a[i];
end;
writeln('Co ',d,' so nguyen to trong day');
write('Tong cac so nguyen to trong day la: ',t);
readln
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem,t,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;
t:=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
begin
inc(dem);
t:=t+a[i];
end;
end;
writeln('So luong so nguyen to la: ',dem);
writeln('Tong cac so nguyen to la: ',t);
readln;
end.
program dem;
var
n, i, chan, le: integer;
a: array[1..1000] of integer;
begin
write('Nhap so phan tu cua day: ');
readln(n);
for i := 1 to n do
begin
write('Nhap phan tu thu ', i, ': ');
readln(a[i]);
end;
chan := 0;
le := 0;
for i := 1 to n do
begin
if (a[i] mod 2 = 0) then
chan := chan + 1
else
le := le + 1;
end;
writeln('So phan tu chan trong day la: ', chan);
writeln('So phan tu le trong day la: ', le);
end.
var n,i,k,d: integer;
a:array[1..52] of integer;
begin
write('Nhap so N: '); readln(n);
for i:=1 to n do
begin
write('a[',i,'] = '); readln(a[i]);
end;
write('Nhap so k: '); readln(k);
d:=0;
for i:=1 to n do
if a[i] mod k = 0 then d:=d+1;
writeln('Co ',d,' so chia het cho ',k,' trong day');
if d mod 2 = 0 then writeln('Chan') else writeln('Le');
end.
uses crt;
var a:array[1..52]of integer;
i,n,k,dem:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=52);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
dem:=0;
for i:=1 to n do
if a[i] mod k=0 then inc(dem);
writeln('Trong day co ',dem,' so chia het cho ',k);
if dem mod 2=0 then writeln('So luong so chia het cho ',k,' la so chan')
else writeln('So luong so chia het cho ',k,' la so le');
readln;
end.
Bài 1:
Program HOC24;
var i,n,d : byte;
t: integer;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,' : '); readln(a[i]);
end;
for i:=1 to n do if (a[i] mod 3=0) and (a[i] mod 5=0) then
begin
d:=d+1;
t:=t+a[i];
end;
writeln('Co ',d,' phan tu la boi cua 3 va 5');
write('Tong la: ',t);
readln
end.
Bài 2:
Program HOC24;
var i,n,k : byte;
begin
write('Nhap N: '); readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,' : '); readln(a[i]);
end;
write('Nhap k: '); readln(k);
for i:=1 to n do if a[i]=k then d:=d+1;
writeln('Co ',d,' phan tu bang ',k);
Write('Cac chi so do la: ');
for i:=1 to n do if a[i]=k then write(i,' ');
readln
end.
uses crt;
var a:array[1..100]of integer;
i,n,dem,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Cac so chan la: ');
dem:=0;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
write(a[i]:4);
t:=t+a[i];
inc(dem);
end;
writeln('Tong cac so chan la: ',t);
writeln('Trong day co ',dem,' so chan');
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[1000],i,n,t,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
for (i=1; i<=n; i++) t+=a[i];
cout<<fixed<<setprecision(2)<<(t*1.0)/(n*1.0)<<endl;
dem=0;
for (i=1; i<=n; i++)
if (i%2==0) dem++;
cout<<dem;
return 0;
}
uses crt;
var a:array[1..100]of integer;
n,i,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('So phan tu chan la: ',dem);
readln;
end.