注册 登录
编程论坛 Delphi论坛

求5个数的阶乘

wangguyu 发布于 2008-05-24 16:26, 1534 次点击
求5个数的阶乘
3 回复
#2
2008-06-01 08:07
function jiecheng(N:integer):real;
var
  m:real;
begin
m:=1;
  for i:=1 to N do
    m:=m*i;
  result:=m;
end;
#3
lisatisfy2008-07-25 17:28
分享下。3Q
#4
ask1234562010-01-15 18:17
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  fac:integer;
  n,i:integer;
begin
  n:=strtoint(inputbox('输入','输入一个不太大的整数','5'));
  label1.Caption :=inttostr(n);
  fac:=1;
  for i:=n downto 2 do
  fac:=fac*i;
  label1.caption:=inttostr(n)+'!='+inttostr(fac);

end;

end.
1