<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> /*js實現:迴圈輸出1000以內水仙花數*/ var a,b,c ; ...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
/*js實現:迴圈輸出1000以內水仙花數*/
var a,b,c ;
for(i=100;i<1000;i++)
{
var a = parseInt(i%10); //個位數
var b = parseInt((i/10)%10); //十位數
var c = parseInt(i/100); //百位數
if(a*a*a+b*b*b+c*c*c== i)
{
document.write(i +"是水仙花數"+"<br/>");
}
}
</script>
</body>
</html>