procedure TForm1.Button1Click(Sender: TObject);
var temp,s,i,j:integer;
begin
s:=1;
while s<100 do
begin
 for i:=1 to 100 do
 begin
 temp:=1;
 for j:=1 to i do
 temp:=temp*i;
 s:=s*temp;
 end;
end;
label1.caption:=inttostr(s);
end;
运行时label里面没有结果,这是哪里错了,求高人指教

解决方案 »

  1.   

    while循环一次,s值就超出了Integer表示的范围,超出了范围会变成负数,最后会变成0所以while这个循环就一直在执行,死循环了
      

  2.   

    大整数算法
    rsa算法必需的
      

  3.   

    按我的理解,结果也只不过是“S=25401600, N=7”(当N=8时,S = 1625702400)。难道我的理解有问题?
    procedure Test;
    var
      s,n,t: Integer;
    begin
      n := 0;
      t := 1;
      s := 1;
      repeat
        inc(n);
        s := t;
        t := S * N * N;
      until t > 100000000;
      Dec(N);  ShowMessage(Format('S=%d, N=%d, t=%d',[s, n, t]));
    end;
      

  4.   

    楼主的算法S结果是:阶乘再乘以阶乘比如for i:=1 to 100 do,当i=8时,是多少呢? 就是1*2!*3!*4!*5!*6!*7!*8!
    继续循环下去,结果真不敢想象呀,而外面还有while循环
      

  5.   

    只能说是它条件下错了,是不是想当 s > 100000000 时退出循环,那应该在循环体内用break退出
      

  6.   

    抱歉,代码当中把 N * N当成 N^N了。
      

  7.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        procedure FormPaint(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormPaint(Sender: TObject);
    var temp,s,i,j:dword;
        n:integer;
        Overflow:boolean;
    begin
      s:=1;
      n:=0;
      Overflow:=false;
      for i:=1 to 100 do
      begin
        temp:=i;
        for j:=2 to i do
          if (temp*temp>100000000)or(temp*temp<1) then
          begin
            Overflow:=true;
            break;
          end
          else temp:=temp*i;
        if Overflow then break
        else if (temp*s>100000000)or(temp*s<1) then break
        else s:=s*temp;
        inc(n);
        Canvas.TextOut(30,n*20,inttostr(temp)+'   n='+inttostr(n));
      end;
      Canvas.TextOut(30,(n+1)*20,format('合题意的数为:%d ; n = %d ',[s,n]));
    end;end.
      

  8.   

    NOIP教程中一段高精度阶乘算法:program factCalc;
    {$APPTYPE CONSOLE}
    var
      i,j,n,w : longint;
      a : array[1..1000] of integer;procedure fact(k : longint);
    var
      x,i : longint;
    begin
      x := 0;
      for i := 1 to w do
      begin
        a[i] := a[i]*k+x;
        x := a[i] div 10;
        a[i] := a[i] mod 10;
      end;
      while x>0 DO
      begin
        w := w+1;
        a[w] := x mod 10;
        x := x div 10;
      end;
    end;begin
      a[1] := 1;
      w := 1;
      readln(n);
      for i := 1 to n do fact(i);
      for j := w downto 1 do write(a[j]);
    end.
      

  9.   


    procedure TSDIAppForm.Button4Click(Sender: TObject);
        Function NMN(i:Integer): Integer;
        Begin
               Result:= Ceil(Power(i,i));
        End;
    var
        S, Temp: Int64;
        I: Integer;
    begin
        S := 1;    for I := 1 to 100 do
        Begin
            Temp := NMN(I);
            S := S * Temp;        if S >100000000 then
            Begin
                lblResult.Caption := FloatToStr(S / Temp);
                Break;
            End;
        End;
    end;lz是要求 1 到 N 的 N的N次方 相乘吗? 并且最终结果不大于 1000000000
    如果是的话,这个代码你看结果是你要的吗
      

  10.   

    后来用if 和 break做出来了,while并不适合这一题,感谢大家