-1
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)

Kitty
  • 13
  • 2
  • 2
    This is obviously homework, and unfortunately SO isn't a homework- doing service. Yuur next step is to re-think what you are doing: you are expecting the user to type in 40 integer values, but you will never be able to debug the inevitable errors in your code unless you can reproduce them and to do that, you need a record of the matrix's contents. So, your first coding task should be to fill the matrix by reading the 40 matrix values from a text-file. Good luck! – MartynA Apr 22 '18 at 17:53
  • @MartynA Actually it could be done simply by calling `test.exe < file.txt` without changing the code... – Abelisto Apr 22 '18 at 20:13
  • @Abelisto: Fair comment, but I am pretty sure that distracting the OP with input/output redirection would not be helpful at his/her current level of competence, so I think it is a red herring, frankly ... – MartynA Apr 22 '18 at 20:30
  • @MartynA: ISTM that if he uses the file redirection, he can keep the code he already has, so that would be less confusing. You ask him to open a file, read values from it and then close it again and probably handle any I/O erros as well. That is not really trivial, and may distract much more, at his level of competence, than simply typing `test.exe < file.txt`. Especially since beginners tend to do everything in one big run, i.e. without subroutines. – Rudy Velthuis Apr 23 '18 at 23:39

1 Answers1

2

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]

Abelisto
  • 14,826
  • 2
  • 33
  • 41