Вычислить сумму элементов файла myfile.dat — Pascal(Паскаль)

В файле
4 2 0 -2 -3 1 1 -1 56
var
  f: text;
  s: integer;
  sum: longint;

BEGIN
  assign(f, '2.txt');
  reset(f);
  while not eof(f) do
  begin
    read(f, s);
    write(s:3);
    inc(sum, s);
  end;
  close(f);
  writeln;
  writeln(sum);

END.

Leave a Comment

− 5 = 5