In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you how to use javascript programming for the number of daffodils, I hope you have some harvest after reading this article, let's discuss it together!
Use javascript programming to find the number of narcissus method: 1, the use of for loop search traverse all three digits;2, determine whether the number traversed is the number of the third power of the number of digits is equal to the number itself;3, respectively, select a hundred-digit number;4, with the if statement to determine whether i is the number of narcissus can be.
Operating environment of this article: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.
First, we need to know what the number of narcissus is:
A narcissus number, also known as a perfect digital invariant (PPDI), narcissistic number, self-power number, Armstrong number, or Armstrong number, is a three-digit number whose sum of the numbers in each digit to the third power equals itself. For example: 1^3 + 5^3+ 3^3 = 153.
Get the number of daffodils through JS:
Thinking analysis:
1. Use the for loop to search through all three digits from 100 to 999;
2. Determine whether the number traversed is the sum of the third power of each single digit number is equal to the number itself. If it is, it is the number of narcissus, and it is output on the console (how to select each single digit).
(1) Select the single digits modulo 10, and the remainder is the single digits.
(2) Divide the ten-digit number i by 10 and round the result to a two-digit integer. modulo 10 with this result to get a ten-digit number
(3) Take the hundred-digit three-digit number and divide it by 100, and then round it to get the hundred-digit number.
3. Use the if statement to determine whether i is the number of daffodils. Math objects are used to perform math tasks, and pow(x , y) functions are used to raise x to the power of y.
for(var i = 100;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.