满意答案
maylcc
2013.04.02
采纳率:48% 等级:12
已帮助:4893人
给一个DELPHI的例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetAverageValue:real;
var
a: Array[0..4] of real;
t:real;
i:integer;
begin
Randomize;
for i:=0 to 4 do
begin
a[i]:=random;
t:=t+a[i];
end;
Result:=t/5;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Button1.Caption:=floattostr(GetAverageValue);
end;
end.
//在delphi里random()不是math的,是system的。
01分享举报