This article will introduce to you how to implement the daffodil number in JavaScript. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Narcissistic number is also known as pluperfect digital invariant (PPDI), narcissistic number, self-exponentiation number, Arms Strong number or Armstrong number (Armstrong number), the narcissus number refers to a 3-digit number, the sum of the third power of the digits in each digit is equal to itself (for example: 1^3 5^3 3^3 = 153).
The following code uses javascript to implement the daffodil number:
for(var i=100;i<1000;i++) { var a=parseInt(i/100); var b=parseInt((i-a*100)/10); var c=parseInt(i%10); // document.write(b); if(i==a*a*a+b*b*b+c*c*c) { document.write(i+"<br/>"); } }
Among them: the method of obtaining the middle digit number can be obtained in a variety of ways: each Individual methods may be different: For example,
for(var i=100;i<1000;i++) { var a=parseInt(i/100); // var b=parseInt((i-a*100)/10); var b=parseInt((i/10)%10); var c=parseInt(i%10); // document.write(b); if(i==a*a*a+b*b*b+c*c*c) { document.write(i+"<br/>"); } }
for narcissus numbers, they are actually a kind of auto-exponentiation number. These numbers all satisfy (n digits, and the sum of the nth power of each digit is equal to its itself);
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to implement narcissus number in javascript. For more information, please follow other related articles on the PHP Chinese website!