1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6     <style>
 7         #result{
 8             margin-top: 20px;
 9             border-top: 2px solid #ccc;
10         }
11     </style>
12 
13     <script type="text/javascript">
14 
15         function isFlowerNum(num){
16 
17             var size = checkLength(num);
18     
19             var temp = num;
20 
21             var sum = 0;
22 
23              while(temp>0){
24                  sum += Math.floor(Math.pow(temp%10,size));
25                  temp=Math.floor(temp/10);
26              }
27 
28                 return sum == num;
29 
30         }
31         
32 
33         function checkLength(num){
34             return (num+"").length;
35         }
36         //alert(checkLength(1235));
37         alert(isFlowerNum(154));
38     </script>
39 
40 </head>
41 <body>
42     <h3>求某长度水仙花数</h3>
43     <div>
44         <label for="size">位数</label>
45         <input type="text" id="size" value="3">
46         <button>查找</button>
47     </div>
48     <div id="result">
49         
50     </div>
51 
52 </body>
53 </html>

 

posted on 2017-04-04 01:18  随心随行  阅读(721)  评论(0)    收藏  举报