pascalfreepascalturbo-pascal

Find the largest absolute value of negative elements for each row of the matrix A (5,8) and rearrange them to first column


program test (input,output);
var
  a:array[1..5, 1..8] of integer;
  n,max,i,j:integer
begin
   writeln('enter massive 5*8');
   for i:=1 to 5 do
   for j:=1 to 8 do
   readln(a[i,j]);

Find the largest absolute value of negative elements for each row of the matrix A (5,8) and rearrange them to first column. Don't know what is the next step!What is my next step in this code?Please, help me)


Solution

  • Hint: you could to declare your matrix in a bit different way:

    type
      TMatrixRow = array[1..8] of Iteger;
      TMatrix = array[1..5] of TMatrixRow;
    var
      a: TMatrix;
    

    Then create procedure that rearranges row's values as you need:

    procedure RearrangeRow(var r: TMatrixRow);
    begin
      // Your code here
    end;
    

    Finally call this procedure for each row:

    for i := 1 to 5 do
      RearrangeRow(a[i]);
    

    Note that you still able to access matrix elements in usual way like a[row, column]