câu 1:
uses crt;
var a,:array[1..100]of integer;
i,n,dem1,dem2,t1,t2:integer;
tbc,tbl:real;
begin
clrscr;
write('nhap so phan tu:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
if a[i]=0 then exit;
end;
{-------------------------------------------------}
for i:=1 to n do write(a[i]:4);
{---------------------------------------------------}
writeln;
dem1:=0;
dem2:=0;
t1:=0;
t2:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
inc(dem1);
t1:=t1+a[i];
end;
if a[i] mod 2=1 then
begin
inc(dem2);
t2:=t2+a[i];
end;
end;
tbc:=t1/dem1;
tbl:=t2/dem2;
writeln('trung binh cac so chan la: ',tbc:4:2);
writeln('trung binh cac so le la: ',tbl:4:2);
readln;
end.
câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,dem:integer;
begin
clrscr;
write('nhap so phan tu:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------------------------}
for i:=1 to n do write(a[i]:4);
{---------------------------------------------------}
writeln;
dem:=0;
for i:=1 to n do
if a[i] mod 3=0 then inc(dem);
writeln('so phan tu chia het cho 3 la: ',dem);
readln;
end.