代码:
<!DOCTYPE html
>
<html>
<head>
<meta charset
="utf-8">
<title>所有的
3位水仙花数
</title
>
</head
>
<body>
<script>
for(var i
= 100 ; i
< 1000 ; i
++){
var hundreds
= parseInt(i
/ 100);
var decade
= parseInt(i
/ 10 % 10);
var unit
= parseInt(i
% 10);
if(i
== (hundreds
*hundreds
*hundreds
+ decade
*decade
*decade
+ unit
*unit
*unit
)){
document
.write("水仙花数为:"+ i
+ "<br/>");
}
}
</script
>
</body
>
</html
>
运行结果:
转载请注明原文地址: https://lol.8miu.com/read-22021.html