Найти полусумму непарных элементов парных столбцов — Delphi(Делфи)

Размер матрицы — 8×9. Формула для определения элементов массива Ai, j=5(i-1)+i*j.

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    SG1: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  n = 8;
  m = 9;
var
  a: array [1 .. n, 1 .. m] of integer;
  i, j: byte;
  ps: real;
begin
  randomize;
  For i := 1 to n do
    For j := 1 to m do
      a[i, j] := random(100);
  ps := 0;
  for i := 1 to n do
  begin
    for j := 1 to m do
    begin
      a[i, j] := 5 * (i - 1) + i * j;
      if (i mod 2 <> 0) and (j mod 2 = 0) then
        ps := ps + a[i, j];
      SG1.Cells[j, i] := inttostr(a[i, j]);
    end;
    ps := ps / 2;
    SG1.Cells[j, i] := inttostr(a[i, j]);
  end;

end.\ \ Две остальных кнопки это кнопки " Очистить " и " Закрыть ".

Leave a Comment

1 + 3 =