試用javascript程式設計,實現計算並輸出100到500的之間的水仙花數(水仙花數是指該數的值等於各位數字的立方和
- 2022-09-08
var result=[];
for(var i=100,temp;i<=999;i++){
temp=i+‘’。split(‘’);
if(i==(math。pow(parseint(temp[0],10),3)+math。pow(parseint(temp[1],10),3)+math。pow(parseint(temp[2],10),3))){
result。push(i);
}
}
alert(result);
//153,370,371,407
<;script>;
for (var i=100; i<;=500; i++)
{
var t = i + ";";;
var x = t。charAt(0) * 1;
var y = t。charAt(1) * 1;
var z = t。charAt(2) * 1;
if ((Math。pow(x,3) + Math。pow(y,3) + Math。pow(z,3)) == i)
{
alert(i);
}
}
<;/script>;
for (var i=100; i<=500; i++)
{
if ( i == eval((i+“”)。replace(/(\d)/g,“Math。pow($1,3)+”)+“0”) ){
document。writeln(i);
}
}