- Related Questions & Answers
- Maximum Product of Two Numbers in a List of Integers in JavaScript
- Product of two number using HOC - JavaScript
- How to sum two integers without using arithmetic operators in C/C++?
- How to sum two integers without using arithmetic operators in C/C++ Program?
- How to find the product of two binary numbers using C#?
- How to get almost increasing sequence of integers in JavaScript ?
- Subtracting two numbers without using the (-) sign JavaScript
- Cartesian product of two sets in JavaScript
- Python Program to Find the Product of two Numbers Using Recursion
- How to get the code name and product name of the browser in JavaScript?
- Given an array of integers, find the pair of adjacent elements that has the largest product and return that product JavaScript
- Returning reverse array of integers using JavaScript
- Java program to calculate the product of two numbers
- Maximum product of any two adjacent elements in JavaScript
- Random whole number between two integers JavaScript

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

We are required to write a function that takes in two numbers and returns their product, but without using the (*) operator.

We know that multiplication and division are just the inverse of each other, so if we divide a number by other number’s inverse, won’t it be same as multiplying the two numbers?

Let’s see the code for this −

const a = 20, b = 45; const product = (a, b) => a / (1 / b); console.log(product(a, b));

Let’s examine the properties of logarithms first −

log(a) + log(b) = log(ab)

So, let’s use this property of logarithms to our good. The code for this will be −

const a = 20, b = 45; const product = (a, b) => { const logProduct = Math.log(a) + Math.log(b); return Math.round(Math.exp(logProduct)); }; console.log(product(a, b));

The output in the console for both will be −

900

Advertisements