Nhập vào n số nguyên từ bàn phím. Tính tổng các số chẵn và tổng các số lẻ của n số vừa nhập. Cám ơn ạ

2 câu trả lời

uses crt;
var a:array[1..1000000] of longint;n,i,s,sl:longint;
begin
   clrscr;
   write('Nhap so luong phan tu: '); readln(n);
   for i:=1 to n do 
      begin
         write('Phan tu thu ',i,': '); read(a[i]);
         if a[i] mod 2=0 then inc(s,a[i]);
         if a[i] mod 2=1 then inc(sl,a[i]);
      end;
   writeln('Tong chan: ',s);
   writeln('Tong le: ',sl);
   readln
end.

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;
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);
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.