码迷,mamicode.com
首页 > Web开发 > 详细

js的水仙花数的输出

时间:2016-07-04 08:51:41      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
var num = [];
var j = 0;
for(var i = 100; i < 1000; i ++){
var iG, iS, iB;
iG = i % 10;
iS = parseInt(i / 10) % 10;
iB = parseInt(i / 100);
var sum = iG*iG*iG + iS*iS*iS + iB*iB*iB;
if(i == sum){
num[j] = i;
j ++;
}
}
document.write("水仙花数都有:" + "<br />");
for(var i = 0; i < num.length; i ++){
document.write(num[i] + "<br />");
}
</script>
</head>
<body>

</body>
</html>

js的水仙花数的输出

标签:

原文地址:http://www.cnblogs.com/SmallPotatoIT/p/5639377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!