R
ReStart
Unregistered / Unconfirmed
GUEST, unregistred user!
我学到函数了,试定义了一个返回1到10的阶乘的和的函数Sumfac,可是为什么通不过呢?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
function Sumfac:Integer;
procedure Edit1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function Sumfac:Integer;
var
I,S:Integer;
begin
Result:=1;
for I:=1 to 10 do
begin
Result:=Result*I;
S:=S+Result;
end;
Sumfac:=S;
end;
{$R *.DFM}
procedure TForm1.Edit1Click(Sender: TObject);
begin
edit1.text:=IntToStr(Sumfac);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
function Sumfac:Integer;
procedure Edit1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function Sumfac:Integer;
var
I,S:Integer;
begin
Result:=1;
for I:=1 to 10 do
begin
Result:=Result*I;
S:=S+Result;
end;
Sumfac:=S;
end;
{$R *.DFM}
procedure TForm1.Edit1Click(Sender: TObject);
begin
edit1.text:=IntToStr(Sumfac);
end;
end.