var B:array[1..32000] of integer;
i,tong1,tong2,n:integer;
begin
writeln('nhap do dai cua day so:'); readln(n);
for i:=1 to n do
begin
write('b[',i,']='); readln(b[i]);
end;
tong1:=0; tong2:=0;
for i:=1 to n do
begin
if b[i] mod 2=0 then tong1:=tong1+b[i];
if b[i] mod 2=1 then tong2:=tong2+b[i];
end;
writeln('tong so chan la:',tong1);
writeln('tong so le la:',tong2);
readln
end.
Lời giải :
program hotrotinhoc ;
var B: array[1..32000] of integer ;
i,n,tong1,tong2 : integer ;
begin
write('n='); readln(n);
writeln('Nhap gia tri cua cac phan tu trong mang B');
for i:= 1 to n do
begin
write('B[',i,']='); readln(B[i]);
end;
tong1:=0 ; tong2:=0;
for i:= 1 to n do
begin
if a[i] mod 2 <> 0 then tong1:=tong1+a[i] ;
if a[i] mod 2 <> 1 then tong2:=tong2+a[i];
end;
writeln('Tong cac so le la :',tong1);
write('Tong cac so chan la:',tong2);
readln
end.