在C中可以求水仙花数在delphi 如何实现 呢?

解决方案 »

  1.   

    var
      i,j,k,l:Integer;
      s:String;
    begin
      s:='水仙花数为:'#13;
      for i:=100 to 999 do
      begin
        //百位数
        j:=Trunc(i/100);    //十位数
        k:=i-j*100;
        k:=Trunc(k/10);    //个位数
        l:=i-j*100-k*10;    if i=j*j*j+k*k*k+l*l*l then//是水仙花数
          s:=s+IntToStr(i)+#13;
      end;  ShowMessage(s);
    end;
      

  2.   

    private
        { Private declarations }
        function sxhs(int_i,int_len:Integer):Integer;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    function tform1.sxhs(int_i,int_len:Integer):Integer;
    var
     i:integer;
     s:Integer;
    begin
         s:=0;
         for i:=1 to int_len do
         begin
             s:=s+ StrToInt(copy(IntToStr(int_i),i,1) )*StrToInt(copy(IntToStr(int_i),i,1) )*StrToInt(copy(IntToStr(int_i),i,1) )
         end;
         if s=int_i then Result:=int_i
         else Result:=0
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
     i:integer;
    begin
        Label1.Caption:='';
        for i:=1 to StrToInt(Edit1.Text) do
        begin
          if sxhs(i,Length(IntToStr(i)))>0 then
          Label1.Caption:=Label1.Caption+' '+IntToStr(i);
        end;
    end;
      

  3.   

    中学生的书都有的,呵呵http://lysoft.7u7.net
      

  4.   

    for i:=1 to 9 do
     for j:=0 to 9 do
      for k:=0 to 9 do
        if 100*i+10*j+k=i*i*i+j*j*j+k*k*k then s:=s+inttostr(i*100+j*10+k)+#13;
    showmessage(s);