
16.04.2008, 13:08
|
Активный
|
|
Регистрация: 24.03.2008
Сообщения: 227
Версия Delphi: Delphi 7
Репутация: 30
|
|
Я бы так это делал.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
StringGrid1: TStringGrid;
Edit1: TEdit;
Button1: TButton;
StringGrid2: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Const
N=10;M=15;Z=25;
var
Form1: TForm1;
C: array [0..N] of integer;
T: array [0..M] of integer;
B: array [0..Z] of integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,p,d,max:integer;
chislo:integer;
begin
StringGrid1.Refresh;
label1.Caption:='';
label2.Caption:='';
chislo:=StrToInt(edit1.Text);
StringGrid1.Cells[0,1]:='C';
StringGrid1.Cells[0,2]:='T';
for i:=1 to N do
begin
C[i]:=random(100);
StringGrid1.Cells[i,1]:=IntToStr(C[i]);
end;
for i:=0 to M do
begin
T[i]:=random(100);
StringGrid1.Cells[i+1,2]:=IntToStr(T[i]);
end;
d:=-1;
for i:=0 to N do
begin
if (C[i]>chislo) then
begin
d:=d+1;
B[d]:=C[i];
end;
end;
for i:=0 to M do
begin
if (T[i]>chislo) then
begin
d:=d+1;
B[d]:=T[i];
end;
end;
StringGrid2.ColCount:=d;
StringGrid2.Cells[0,1]:='B';
for i:=0 to d do
begin
StringGrid2.Cells[i+1,1]:=IntToStr(B[i]);
end;
p:=1;
for i:=0 to d do
begin
p:=p*b[i];
end;
label1.Caption:='Âñåãî ýëåìåíòîâ: '+IntToStr(d);
label2.Caption:='Ïðîèçâåäåíèå ýëåìåíòîâ ìàññèâà: '+IntToStr(p);
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
For i:=0 to M-1 do
StringGrid1.ColWidths[i]:=Trunc(StringGrid1.Width /M);
end;
end.
|