Найти нулевые элементы матрицы А [5,5] под диагональю, противоположной главной- Pascal(Паскаль)

пример входного файла

1 2 3 0 5
0 2 5 0 0
5 4 0 2 0
0 8 1 0 0
2 0 3 0 3
const
  n= 5;
type
  tMatrix = array [1..n,1..n] of integer;
 
function NextZeroInRow(A: tMatrix; i,j: integer): integer;
{returns position of next zero in a row i of matrix A starting at position j; if no zeros found, will return 0}
begin
  while (j<=n) and (A[i,j]<>0) do Inc(j);
  NextZeroInRow:= j mod (n+1)
end;
 
var
  A: tMatrix;
  f: text;
  i,j: integer;
 
begin
  Assign(f,'in.txt');
  Reset(f);
  for i:=1 to n do begin
    for j:=1 to n do read(f,a[i,j]);
    readln(f)
  end;
  Close(f);
  for i:=1 to n do begin
    for j:=1 to n do write(a[i,j]:4);
    writeln
  end;
  for i:=2 to n do begin
    j:=n-i+2;
    while j>0 do begin
      j:= NextZeroInRow(A,i,j);
      if j>0 then begin
        writeln('Zero element found at position ',i,',',j);
        Inc(j)
      end
    end
  end;
  writeln('Search done.');
  readln
end.

Leave a Comment

12 − 4 =