
13.06.2013, 15:56
|
 |
Активный
|
|
Регистрация: 06.06.2010
Сообщения: 340
Версия Delphi: 11.3
Репутация: 429
|
|
Предлагаю свой вариант решения:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Math, StdCtrls, Grids;
type
TForm1 = class(TForm)
SG1: TStringGrid;
Button1: TButton;
SG2: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
aMin = 0; aMax = 9;
var
Form1: TForm1;
aRnd: array [aMin..aMax, aMin..aMax] of SmallInt;
implementation
{$R *.dfm}
procedure FillArray;
var
I, J: SmallInt;
begin
for I := aMin to aMax do
for J := aMin to aMax do
aRnd[I, J] := RandomRange(-25, 25);
end;
procedure ChangeSign(Col, Row: Byte);
var
I: SmallInt;
begin
for I := aMin to aMax do
if (I <> Col) and (I <> Row) then
begin
aRnd[I, Row] := aRnd[I, Row] * (-1);
aRnd[Col, I] := aRnd[Col, I] * (-1);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
C, R: SmallInt;
begin
FillArray;
for R := aMin to aMax do
for C := aMin to aMax do
SG1.Cells[R, C] := IntToStr(aRnd[R, C]);
ChangeSign(4, 4);
for R := aMin to aMax do
for C := aMin to aMax do
SG2.Cells[R, C] := IntToStr(aRnd[R, C]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
end;
end.
__________________
Всегда пишите код так, будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете.
|