Дан двумерный массив размерности 10х10. Заполнить его случайными числами на отрезке [-25,25]. Заменить все элементы k-й строки и s-го столбца массива противоположными по знаку (элемент, стоящий на пересечении строки и столбца, не изменять). Вывести исходный массив и полученный результат на печать.
в delphi,пожалуйста
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.