Print Strong Numbers Within a Range using JavaScript Last Updated : 14 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In mathematics, a strong number is a number whose sum of the factorial of its digits is equal to the number itself. The task is to print all strong numbers within a given range in JavaScript. Example: 145 is a Strong number because: 1: 14: 4*3*2*1=245: 5*4*3*2*1=120120+24+1=145Since the sum is equal to number, 145 is a Strong number. Table of Content Iterative Approach:Recursive Approach:Iterative ApproachIn this approach, we iterate through the range of numbers and for each number, we calculate the sum of the factorials of its digits iteratively. Then, we check if this sum is equal to the original number. Example: The below code print Strong Numbers Within a Range using Iterative Approach in JavaScript. JavaScript function factorial(num) { let fact = 1; for (let i = 2; i <= num; i++) { fact *= i; } return fact; } function sumOfFactorialOfDigits(number) { let sum = 0; let temp = number; while (temp > 0) { let digit = temp % 10; sum += factorial(digit); temp = Math.floor(temp / 10); } return sum; } function printStrongNumbersInRange(start, end) { for (let i = start; i <= end; i++) { if (sumOfFactorialOfDigits(i) === i) { console.log(i); } } } printStrongNumbersInRange(1, 1000); Output1 2 145 Recursive ApproachIn this approach, we define a recursive function to calculate the sum of the factorials of the digits of a number. Then, we iterate through the range of numbers and for each number, we call this recursive function to check if it is a strong number. Example: The below code print Strong Numbers Within a Range using Recursive Approach in JavaScript. JavaScript function factorial(num) { if (num === 0 || num === 1) { return 1; } else { return num * factorial(num - 1); } } function sumOfFactorialOfDigits(number) { if (number === 0) { return 0; } else { let digit = number % 10; return factorial(digit) + sumOfFactorialOfDigits(Math.floor(number / 10)); } } function isStrongNumber(number) { return sumOfFactorialOfDigits(number) === number; } function printStrongNumbersInRange(start, end) { for (let i = start; i <= end; i++) { if (isStrongNumber(i)) { console.log(i); } } } printStrongNumbersInRange(1, 1000); Output1 2 145 Comment More infoAdvertise with us Next Article Print Strong Numbers Within a Range using JavaScript A anjugaeu01 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to print a web page using JavaScript ? Javascript is the world most popular lightweight, cross-platform, interpreted compiled programming language, along with a scripting language for web. It facilitates the dynamic functionality that helps to make the interactive website. As all the Morden browsers use the Javascript & is a client-s 2 min read Generate Random Number in Given Range Using JavaScript Here are the different ways to generate random numbers in a given range using JavaScript1. Using Math.random(): basic ApproachThis is the simplest way to generate a random number within a range using Math.random().JavaScriptlet min = 10; let max = 20; let random = Math.floor(Math.random() * (max - m 3 min read How to print a number with commas as thousands separators in JavaScript? Method 1: Using Intl.NumberFormat() The Intl.NumberFormat() object is used to represent numbers in language-sensitive formatting. It can be used to represent currency or percentages according to the locale specified.The locales parameter of this object is used to specify the format of the number. Th 2 min read Extract a Number from a String using JavaScript We will extract the numbers if they exist in a given string. We will have a string and we need to print the numbers that are present in the given string in the console.Below are the methods to extract a number from string using JavaScript:Table of ContentUsing JavaScript match method with regExUsing 4 min read Print all Odd Numbers in a Range in JavaScript Array Odd numbers are numbers that cannot be divided into equal parts. If we divide the odd number by 2, the remainder is 1. In JavaScript, if we want to print all Odd numbers in a range, we can print it by iterating over the array, applying the condition, and printing the odd numbers. There are various a 4 min read JavaScript Number Static Properties The JavaScript Number is an object that can represent numeric values like integer, float, hexadecimal, decimal, etc. It acts as a wrapper object for primitive numeric values. It has various methods and properties that are used to perform different tasks on numbers. The following table shows some sta 2 min read How to get decimal portion of a number using JavaScript ? Given a float number, The task is to separate the number into integer and decimal parts using JavaScript. For example, a value of 15.6 would be split into two numbers, i.e. 15 and 0.6 Here are a few methods discussed. These are the following methods: Table of Content Javascript String split() Method 3 min read Print all Even Numbers in a Range in JavaScript Array We have to find all even numbers within a given range. To solve this question we are given the range(start, end) in which we have to find the answer. There are several ways to print all the even numbers in a range in an array using JavaScript which are as follows: Table of Content Using for Loop in 3 min read How to create a Number object using JavaScript ? In this article, we will discuss how to create a Number object using JavaScript. A number object is used to represent integers, decimal or float point numbers, and many more. The primitive wrapper object Number is used to represent and handle numbers. examples: 20, 0.25. We generally don't need to w 2 min read Set of pairs of numbers in JavaScript To Access all sets of pairs of Numbers in an array, We need to access all possible pairs of numbers and need to apply conditions and other operations. In this article, we will see how to access a pair of numbers in JavaScript using different approaches. The first approach is Nested Loop and the seco 2 min read Like