u_form.pas
来自「很好地delphi书籍源码」· PAS 代码 · 共 87 行
PAS
87 行
unit U_form;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, ExtCtrls;
type
TForm1 = class(TForm)
CalcButton: TButton;
RGroup: TRadioGroup;
procedure CalcButtonClick(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function F1(n: word): word;
begin
if n<=0 then exit
else if n=1 then result:=1
else Result:=n*F1(n-1);
end;
function F2(n: word): word;
var
Loc_sum,i:word;
begin
if n<=0 then exit;
if n=1 then begin result:=1; exit; end;
Loc_sum:=0;
if n>1 then
begin
for i:=1 to n do
Loc_sum:=Loc_sum+i;
end;
result:=F2(n-1)+Loc_sum ;
end;
function F3(n: word): word;
begin
if n<=0 then exit;
if n=1 then begin result:=1; exit; end;
result:=F3(n-1)+F1(n) ;
end;
procedure TForm1.CalcButtonClick(Sender: TObject);
var
Loc_st:string ;
Loc_N:word;
begin
case RGroup.ItemIndex of
0:begin
if InputQuery(RGroup.Items.Strings[0],'N=', Loc_st) then
begin
Loc_N:=StrToInt(Loc_st);
Caption:=Format('%d!=%d',[Loc_N,F1(Loc_N)]);
end;
end;
1:begin
if InputQuery(RGroup.Items.Strings[1],'N=', Loc_st) then
begin
Loc_N:=StrToInt(Loc_st);
Caption:=Format('S=%d',[F2(Loc_N)]);
end;
end;
2:begin
if InputQuery(RGroup.Items.Strings[1],'N=', Loc_st) then
begin
Loc_N:=StrToInt(Loc_st);
Caption:=Format('S=%d',[F3(Loc_N)]);
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?