Advertisement
Askja

Untitled

May 3rd, 2022
1,107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.94 KB | None | 0 0
  1. program SearchMaxNegative;
  2. var
  3.     n, k, j, max, maxIndex: integer;
  4.     matrix: array of array of integer;
  5. begin
  6.     write('n = ');
  7.     readln(n);
  8.  
  9.     setlength(matrix, n, n);
  10.  
  11.     writeln('Before update: ');
  12.     for k := 0 to n - 1 do begin
  13.         max := matrix[k, 0];
  14.         maxIndex := 0;
  15.        
  16.         for j := 0 to n - 1 do begin
  17.             matrix[k, j] := -3 + random(11);
  18.             write(matrix[k, j] : 4, ' ');
  19.            
  20.             if matrix[k, j] > max then begin
  21.                 max := matrix[k, j];
  22.                 maxIndex := j;
  23.             end;
  24.         end;
  25.        
  26.         if (k > 0) and (k < n - 1) then begin
  27.             matrix[k, maxIndex] := 0;
  28.         end;
  29.        
  30.         writeln;
  31.     end;
  32.    
  33.     writeln('After update: ');
  34.     for k := 0 to n - 1 do begin
  35.         for j := 0 to n - 1 do begin
  36.             write(matrix[k, j] : 4, ' ');
  37.         end;
  38.        
  39.         writeln;
  40.     end;
  41. end.
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement