Câu 2:
program tong_chan;
uses crt;
var A:array[1..100] of integer;
n,i,t:integer;
begin
clrscr;
write('Nhap n: '); 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;
write('Tong cac so chan la: ',t);
readln;
end.
Câu 3:
Để ghi dữ liêu vào tệp thì ta cần dùng các thao tác:
Mở tệp để ghi:
+ Mở tệp: Assign(<tên biến tệp>,<tên tệp>);
+ Mở tệp để ghi: rewrite(<tên biến tệp>);
+ Ghi dữ liệu vào tệp: write(<tên biến tệp>,<dữ liệu>);
+ Đóng tệp: close(<tên biến tệp>);
VD: Muốn ghi "Tai sao" vào trong tệp f có tên "CAUHOI.TXT" là:
Assign(f,'CAUHOI.TXT'); rewrite(f);
write(f,'Tai sao');
close(f);