Показать сообщение отдельно
  #9  
Старый 23.01.2012, 16:04
999 999 вне форума
Прохожий
 
Регистрация: 21.01.2012
Сообщения: 5
Репутация: 10
По умолчанию Двухмерный массив в Delphi.Помогите найти ошибку!

Дан двумерный массив размером n*m, заполненный случайным образом.
Заменить минимальный по модулю элемент каждого столбца на противоположный
Код:
var
Form3: TForm3;
  i,j,n,m,min:Integer;
  a:array [0..30,0..30] of integer;

implementation

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
Randomize;
n:=strtoint(Edit1.Text);
m:=strtoint(Edit2.Text);
for i:=0 to n-1 do
for j:=0 to m-1 do
a[i,j]:=Round(Sin(Random(100))*100);
StringGrid1.RowCount:=n+1;
StringGrid1.RowCount:=m+1;
With  StringGrid1 do
begin
  i:=0;
  for J := 1 to RowCount do
  Cells[i,j]:=Inttostr(j);
j:=0;
  for i:= 1 to ColCount do
  Cells[i,j]:=Inttostr(i);
end;
 With  StringGrid1 do
 for i:= 1 to n do
     for j:=1 to m do
   Cells[i,j]:=inttostr(a[i-1,j-1]);
for i:= 1 to n do
begin
  min:=abs(a[1,1]);
 for I := 0 to n-1 do
  if abs(a[i,j])< abs(min) then  min:=a[i,j];
end;
  for i:= 1 to n do
  for j:=1 to m do
  begin
 a[i,j]:=-a[i,j];
 end;
With  StringGrid2 do
begin
  i:=0;
  for J := 1 to RowCount do
  Cells[i,j]:=Inttostr(j);
j:=0;
  for i:= 1 to ColCount do
  Cells[i,j]:=Inttostr(i);
end;
 With  StringGrid2 do
 for i:= 1 to n do
 for j:=1 to m do
Cells[i,j]:=inttostr(a[i-1,j-1]);
end;
end.
Ответить с цитированием