Home > Web Front-end > JS Tutorial > How to implement narcissus number in javascript

How to implement narcissus number in javascript

醉折花枝作酒筹
Release: 2021-04-29 09:23:53
forward
3217 people have browsed it

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.

How to implement narcissus number in javascript

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/>");
				}
			}
Copy after login

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/>");
				}
			}
Copy after login

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!

Related labels:
js
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template