主题:[讨论]帮忙挑错改错,答对给加分
计算文本文件的行长度的平均值、最大值和最小值
var f:text;a:array[1..100]of integer;
i,j,n,max,min:integer;ave:real;
begin
assign(f,'file1.dat');
reset(f);
i:=1;min:=9999;
while not eof(f) do
begin
read(f);
while not eoln(f) do begin inc(j);read(f);end;
a[i]:=j;
inc(i);
end;
for n:=1 to i do
begin
if a[i]<min then min:=a[i];
if a[i]>max then max:=a[i];
ave:=ave+a[i];
end;
ave:=ave/i;
writeln(ave:8:2,max:6,min:6);
close(f);
readln;
end.
var f:text;a:array[1..100]of integer;
i,j,n,max,min:integer;ave:real;
begin
assign(f,'file1.dat');
reset(f);
i:=1;min:=9999;
while not eof(f) do
begin
read(f);
while not eoln(f) do begin inc(j);read(f);end;
a[i]:=j;
inc(i);
end;
for n:=1 to i do
begin
if a[i]<min then min:=a[i];
if a[i]>max then max:=a[i];
ave:=ave+a[i];
end;
ave:=ave/i;
writeln(ave:8:2,max:6,min:6);
close(f);
readln;
end.