In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.