Multiplication Without Using * Operator
Use Recursion to multiply two numbers without using the * operator.
We'll cover the following...
We'll cover the following...
Problem statement
In this problem, we need to find the result of the multiplication of two numbers, a and b but without using * operator. This looks like a pretty simple problem. We can easily iterate a loop from 1 to b and add a to our result. But there is a catch: you need to write a solution with a Recursive approach.
Implementation
Let’s write the solution first, and then visualize how recursion is working.
Explanation:
- On line 4, we define our recursive function
prod(). - On line 5, we check for the base case as