![]() |
Armstrong number is a number equal to the sum of its digits raised to the power 3 of the number of digits. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. This article will explore how to find Armstrong numbers between 1 to 1000 using JavaScript. Approach 1: Display Armstrong Numbers Between 1 to 1000 using a LoopThe simplest approach to finding Armstrong numbers is using a loop to iterate through each number from 1 to 1000 and check if it is an Armstrong number. Javascript
Output
1 2 3 4 5 6 7 8 9 153 370 371 407 Approach 2: Display Armstrong Numbers Between 1 to 1000 using Array MethodsWe can also use JavaScript array methods to make the code more concise and functional. In this approach, we convert the number to a string, split it into an array of digits, and then use the reduce method to calculate the sum of each digit raised to the power of the number of digits. Javascript
Output
1 2 3 4 5 6 7 8 9 153 370 371 407 |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |