Bài 1:
uses crt;
var a:array[1..100]of integer;
n,i,tc,tl:integer;
begin
clrscr;
write('n='); readln(n);
if (0<n) and (n<=100) then
begin
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------tong-cac-so-chan--------------}
tc:=0;
for i:=1 to n do
if a[i] mod 2=0 then tc:=tc+a[i];
writeln('tong cac so chan trong day so la: ',tc);
{------------------tong-cac-so-le------------------}
tl:=0;
for i:=1 to n do
if a[i] mod 2<>0 then tl:=tl+a[i];
writeln('tong cac so le trong day so la: ',tl);
end
else writeln('vui long nhap lai');
readln;
end.
Bài 2:
uses crt;
var a:array[1..100]of integer;
n,i,t,d,t1,j,x,y:integer;
st:string;
begin
clrscr;
write('n='); readln(n);
if (0<n) and (n<=100) then
begin
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------xu-ly-------------}
t:=0;
for i:=1 to n do
begin
str(a[i],st);
d:=length(st);
t1:=0;
for j:=1 to d do
begin
val(st[j],x,y);
t1:=t1+x;
end;
if t1 mod 4=0 then t:=t+a[i];
end;
writeln('tong cac so co tong cac chu so chia het cho 4 trong day la: ',t);
end
else writeln('vui long nhap lai');
readln;
end.