name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3528650120430763&dt=1183890684015&lmt=1183890684&format=468x60_as&output=html&correlator=1183890684000&url=http%3A%2F%2Fgmai9999.googlepages.com%2Fhome&ad_type=text_image&ui=rc%3A0&cc=100&flash=9&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="allowtransparency">
//水仙花数
//题目:打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数
//本身。例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方。
//1.程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。
procedure TForm1.Button2Click(Sender: TObject);
var
i,j,k,l,m : integer;
begin
m := 0;
for i := 100 to 999 do // Iterate
begin
j := i div 100; //百位
k := (i mod 100) div 10;//十位
l := ((i mod 100) mod 10) ;
if i=(j*j*j + k*k*k + l*l*l) then
begin
inc(m);
Memo.Lines.Add(inttostr(m)+'-----'+inttostr(i));
end;
end; // for
end;
name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3528650120430763&dt=1183890684015&lmt=1183890684&format=468x60_as&output=html&correlator=1183890684000&url=http%3A%2F%2Fgmai9999.googlepages.com%2Fhome&ad_type=text_image&ui=rc%3A0&cc=100&flash=9&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="allowtransparency">