Câu 2:
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
t:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t:=t+a[i];
writeln(t);
readln;
end.
Câu 1:
program bai1;
uses crt;
var i,d:integer;
a:array[1..100]of integer;
begin
clrscr;
i:=1;
write('a[',i,']=');readln(a[i]);
repeat
inc(i);
write('a[',i,']=');readln(a[i]);
until a[i]<=0;
d:=i;
writeln('cac so da nhap la:');
for i:=1 to d do
write(a[i]:3);
readln;
end.
Câu 2:
program bai2;
uses crt;
var i,n:integer;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so phan tu cua day so:');readln(n);
for i:=1 to n do
begin
write('a[',i,']=');readln(a[i]);
end;
writeln('cac so le trong day la:');
for i:=1 to n do
if a[i] mod 2<>0 then write(a[i]:3);
readln;
end.
Câu 3:
program bai3;
uses crt;
var i,n:integer;
a:array[1..100]of integer;
t:longint;
begin
clrscr;
write('nhap so phan tu cua day so:');readln(n);
t:=0;
for i:=1 to n do
begin
write('a[',i,']=');readln(a[i]);
if a[i] mod 2=0 then t:=t+a[i];
end;
writeln('tong cac phan tu chan cua day la: ',t);
readln;
end.