cho tệp bt.txt có chứa3 số nguyên dương(<255) a)Đọc 3 giá trị trên b)Ghi tổng các số chẵn vào tệp dulieu.inp ->>em cần gấp ạ 18/07/2021 Bởi Daisy cho tệp bt.txt có chứa3 số nguyên dương(<255) a)Đọc 3 giá trị trên b)Ghi tổng các số chẵn vào tệp dulieu.inp ->>em cần gấp ạ
var f1, f2: text; A: array[1..3] of byte; Tc: word; Begin Assign(f1, ‘bt.txt’); reset(f1); Assign(f2, ‘dulieu.inp’); rewrite(f); Tc:=0; For i:=1 to 3 do Begin Read(f1, a[i]); If (a[i] mod 2 = 0) then tc:=tc+a[i]; End; Write(f2, tc); close(f2); End. Bình luận
var fi,fo: text; i,tong: integer;begin assign(fi,‘bt.txt’); reset(fi); while not eof(fi) do begin readln(fi,i); If i mod 2 = 0 then tong:=tong+i; end; close(fi); assign(fo,‘dulieu.inp’); rewrite(fo); write(fo,tong); close(fo); end. Bình luận
var f1, f2: text;
A: array[1..3] of byte;
Tc: word;
Begin
Assign(f1, ‘bt.txt’); reset(f1);
Assign(f2, ‘dulieu.inp’); rewrite(f);
Tc:=0;
For i:=1 to 3 do
Begin
Read(f1, a[i]);
If (a[i] mod 2 = 0) then tc:=tc+a[i];
End;
Write(f2, tc); close(f2);
End.
var fi,fo: text;
i,tong: integer;
begin
assign(fi,‘bt.txt’);
reset(fi);
while not eof(fi) do
begin
readln(fi,i);
If i mod 2 = 0 then tong:=tong+i;
end;
close(fi);
assign(fo,‘dulieu.inp’);
rewrite(fo);
write(fo,tong);
close(fo);
end.