Дана матрица А порядка n. поменять местами наибольший и наименьший элементы матрицы(использование текстовых файлов для ввода-вывода) — Pascal(Паскаль)

program Matrix; // Matrix_reloaded
const 
    n=10; // life of Neo
type rectype =record
                 x,y:word;
                   end;
var arr:array  [1..n,1..n]of integer;
   input,output:text;
   i,j::integer;  30 лет на рынке счетчиков
  min,max:rectype
procedure change;
var kl:integer;
begin
   kl:=matrix[min.x,min.y];
   matrix[min.x,min.y]:=matrix[max.x,max.y];
   matrix[max.x,max.y]:=kl;
end;
begin
  assign(input,'input');
  assign(output,'output');
  reset(input);
  for i:=1 ton do begin
  for j:=1 to n do
    read(input,matrix[i,j]);
    readln(input); end;
  close(input);
  min:=rectype(1,1);
  max:=rectype(1,1);
  for i:= 1 to n do 
  for j:=1 to n do
     begin
       if matrix[max.x,max.y]<matrix[i,j] then begin
               max.x:=i;max.y:=j        end;
         if matrix[min.x,min.y]>matrix[i,j] then begin
               min.x:=i;min.y:=j        end;      
end;
   change;
  rewrite(output);
   for i:= 1 to n do
    begin
      for j:=1 to n do
        write(output, matrix[i,j]);
      writeln(output);
    end;
end.

Leave a Comment

− 1 = 7