Дана матрица М(5,5). Среди элементов главной диагонали найти наибольший элемент. Вывести его на печать и обнулить строку и столбец, в котором он расположен — Pascal(Паскаль)

uses crt;
const
  str=5;
  sto=5;
var
  a:array [1..str,1..sto] of integer;
  i,j,max,tempi,tempj:integer;
begin
  clrscr;

  writeln('Формирование матрицы:');
  for i:=1 to str do
  begin
    for j:=1 to sto do
    begin
      a[i,j]:=random(8)-4;
      write(a[i,j],' ')
    end;
    writeln
  end;
 
  max:=a[1,1];
  tempi:=1;
  tempj:=1;
  for i:=1 to str do
    for j:=1 to sto do
      if a[i,j]>max then
      begin
        max:=a[i,j];
        tempi:=i;
        tempj:=j
      end;
  writeln('Наибольший ',max,'. среди [',tempi,',',tempj,']');

  for i:=1 to sto do
  begin
    a[tempi,i]:=0;
    a[i,tempj]:=0
  end;
 
  writeln('Итоговая матрица:');
  for i:=1 to str do
  begin
    for j:=1 to sto do
      write(a[i,j],' ');
    writeln
  end;
  writeln
end.

Leave a Comment

43 − 41 =