
12.06.2012, 21:46
|
 |
Новичок
|
|
Регистрация: 08.04.2012
Сообщения: 68
Версия Delphi: Delphi 7
Репутация: 127
|
|
Для массива размерностью m*n (в т.ч. m<>n) вот код:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
StringGrid: TStringGrid;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mas:array of array of integer;
n,m,i,j:byte;
max,min:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
{Добавить сюда процедуры по очистке Label1 и Label2.
Процедуры по очистке ячеек StringGrid }
min:=40; max:=-40;
m:=StrToInt(Edit1.Text);
n:=StrToInt(Edit2.Text);
SetLength(mas,m);
for i:=0 to m-1 do
setLength(mas[i],n);
randomize;
for i:=0 to m-1 do
for j:=0 to n-1 do
begin
mas[i,j]:=random(81)-40;
StringGrid.Cells[j,i]:=IntToStr(mas[i,j]);
if i=j then
if mas[i,j]<min then min:=mas[i,j];
if j=(n-1)-i then
if mas[i,j]>max then max:=mas[i,j];
end;
Label1.Caption:=('Minnimum budet'+#13#10+IntToStr(min));
Label2.Caption:=('Maximum budet'+#13#10+IntToStr(max));
// mas:=nil;
// не забываем очищать память
end;
end.
|