T
T
toyou2017-11-12 20:50:42
Delphi
toyou, 2017-11-12 20:50:42

Why does the dimension of the matrix remain the same?

program Project1;
//To this matrix A of order n, add zero and n + 1 columns with elements equal to 0.
{$APPTYPE CONSOLE}
uses
SysUtils;
type
matr=array[1..10,1..10] of Real;
string=string[30];
var
a, a2:matr;
n,i,j,m:Integer;
flag:Boolean;
procedure vvodmatr(var a:matr;ntd:stroka;var n:Integer; fl1,fl2:Boolean);
var
i,j:Integer;
t:text;
begin
if fl1 then
begin
assign(t,ntd);
reset(t);
end;
read(t,n,n);
for i:=1 to n do
begin
for j:=1 to n do
read(t,a[i,j]);
end;
if fl2 then
close(t);
end;
procedure addavlenie(a:matr;n:Integer; var a2:matr);
var
i,j:integer;
beginm
:=n+2;
for i:=1 to n do
a2[i,m]:=0;
begin
for j:=m downto 1 do
for i:=1 to n do
a2[i,j+1]:=a[i,j];
end;
for i:=1 to n do
a2[i,1]:=0;
end;
procedure vivodmatr(ntd:stroka;a:matr;n:Integer;ntd2:stroka;const flag:boolean);
var
i,j:integer;
t2:text;
begin
Assign(t2,ntd);
if flag then
Rewrite(t2)
else Append(t2);
WriteIn(t2,ntd2);
for i:=1 to n do
begin
for j:=1 to n do
write(t2,a[i,j]:8:2);
writeln(t2);
end;
if ntd='con' then
Readln
else
Close(t2);
end;
begin
vvodmatr(a, 'ntd.txt', n,True,false);
flag:=True;
vivodmatr('ntd2.txt',a,n,'matrix a',flag);
add(a,n,a2);
flag:=False;
vivodmatr('ntd2.txt',a2,n,'matrix a2',flag);
5a0889f0856dc948349864.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Fedoryan, 2017-11-13
@AnnTHony

program mtrx;
const
  N = 5;
var
  matrix: array of array of integer;
  i, j: integer;
begin
  SetLength(matrix, N);
  for i := 0 to N - 1 do
    SetLength(matrix[i], N);

  Randomize;
  
  for i := 0 to N - 1 do
    begin
      for j := 0 to N - 1 do
        begin
          matrix[i, j] := Random(100);
          Write(matrix[i, j]:4);
        end;
      WriteLn();
    end;
  
  WriteLn();
  
  for i := 0 to N - 1 do
    SetLength(matrix[i], N + 2);
  
  for i := 0 to N - 1 do
    for j := N downto 0 do
      matrix[i, j + 1] := matrix[i, j];
  
  for i := 0 to N - 1 do
    begin
      matrix[i, 0] := 0;
      for j := 0 to N + 1 do
        Write(matrix[i, j]:4);
      WriteLn();
    end;
end.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question