Дана квадратная матрица порядка 5. Найти столбец, который обладает наибольшей суммой модулей элементов. Для этого столбца найти наименьшее значение элементов. Если таких столбцов несколько, то взять первый из них — Delphi(Делфи)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Table1: TStringGrid;
    Button1: TButton;
    Label3: TLabel;
    Label4: TLabel;

    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  mas: array [1 .. 6, 1 .. 6] of integer;
  s: array [1 .. 6] of integer;
  max, maxN: integer;
  min: integer;
  i, j: integer;
begin
  for i := 1 to 6 do
  begin
    for j := 1 to 6 do
    begin
      mas[i, j] := Random(100);
      Table1.Cells[i, j] := FloatToStr(mas[i, j]);
    end;
  end;
  for i := 1 to 6 do
  begin
    s[i] := 0;
    for j := 1 to 6 do
    begin
      s[i] := s[i] + abs(mas[i, j]);
    end;
  end;
  max := 1;
  For i := 1 to 6 do
  begin
    if s[i] > max then
    begin
      max := s[i];
      maxN := i;
    end;
  end;
  Label3.Caption := IntToStr(maxN);
  min := 100;
  For j := 1 to 6 do
    if mas[maxN, j] < min then
      min := mas[maxN, j];
  Label4.Caption := IntToStr(min);
end;

end.

Leave a Comment

1 + 6 =