检查下此程序的问题(pascal)

来源:百度知道 编辑:UC知道 时间:2024/05/24 23:40:23
var f,b,a:integer;
begin
assign(input,'d:\1.txt');
assign(output,'d:\2.txt');
reset(input);
rewrite(output);
while not eof(input) do
begin
while not eoln(input) do
begin
read(input,f);
a:=a+f;
end;
b:=b+a;
write(output,b);
end;
close(input);
close(output);
end.

原程序没有语法错误,可以对一行数据进行求和,并将结果存入2.txt文件,但对多于一行数据进行计算时会出现问题,对此,我作了一下修改,使得程序可以对多行数据进行计算,并将相加结果存入2.txt:

var f,b,a:integer;
begin
assign(input,'d:\1.txt');
assign(output,'d:\2.txt');
reset(input);
rewrite(output);
while not eof(input) do
begin
a:=0;
b:=0;
while not eoln(input) do
begin
read(input,f);
a:=a+f;
end;
b:=b+a;
writeln(output,b);
readln(input);
end;
close(input);
close(output);
end.

不知道。。。。。。。。。。。。。。