- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Take two numbers m and n & return two numbers whose sum is n and product m in JavaScript

We are required to write a JavaScript function that takes in two numbers, say m and n and returns two numbers whose sum is n and product is m. If there exist no such numbers, then our function should return false

Let’s write the code for this function −

## Example

const perfectNumbers = (sum, prod) => { for(let i = 0; i < (sum / 2); i++){ if(i * (sum-i) !== prod){ continue; }; return [i, (sum-i)]; }; return false; }; // 12 12 are not two distinct numbers console.log(perfectNumbers(24, 144)); console.log(perfectNumbers(14, 45)); console.log(perfectNumbers(21, 98));

## Output

Following is the output in the console −

false [ 5, 9 ] [ 7, 14 ]

- Related Articles
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N in C++
- Find two numbers whose product is $-24$ and sum is 2.
- Find two numbers whose sum is 27 and product is 182.
- Find two numbers with sum and product both same as N in C++
- Find two numbers with sum and product both same as N in C++ Program
- C++ program to find two numbers with sum and product both same as N
- Implementing Math function and return m^n in JavaScript
- Sum of even numbers from n to m regardless if nm JavaScript
- Sum of two numbers modulo M in C++
- How to check if two numbers (m,n) are amicable or not using Python?
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++
- Write two numbers which differ by 3 and whose product is 54.
- Return the greatest possible product of n numbers from the array in JavaScript
- The product of two numbers is 24 and their sum is 14. Find the numbers.
- The sum of two numbers is 48 and their product is 432. Find the numbers.

Advertisements