Var f:text; ma:array[1..n,1..m] of integer; i,j,s:integer; begin assign(f,'matrix.txt'); reset(f); for i:=1 to n do begin for j:=1 to m do begin read(f,ma[i,j]); s:=s+ma[i,j]; end; end; close(f); for i:=1 to n do begin writeln; for j:=1 to m do write(ma[i,j]:4); end; writeln; write(s); end.
Const
n=3; //количество строк
m=4; //количество столбцов
Var
f:text;
ma:array[1..n,1..m] of integer;
i,j,s:integer;
begin
assign(f,'matrix.txt');
reset(f);
for i:=1 to n do
begin
for j:=1 to m do
begin
read(f,ma[i,j]);
s:=s+ma[i,j];
end;
end;
close(f);
for i:=1 to n do
begin
writeln;
for j:=1 to m do
write(ma[i,j]:4);
end;
writeln;
write(s);
end.
matrix.txt:
1 2 3 4
4 5 6 4
7 8 9 4
Вывод программы:
1 2 3 4
4 5 6 4
7 8 9 4
57