给一个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的。
取消
评论