Hello, everyone, welcome to this new session.
So what we will do today, so we will try to solve one more problem with the help of the council so
that our understanding of religion can become better.
OK, so the name of the problem that we are going to solve today is multiplication.
OK, so what we will do so given two numbers, we have to multiply them.
OK, so there are two numbers, M and N and we have to multiply these two numbers.
So that is M and doing OK.
So the one way to solve this problem is to simply use the multiply operator, but we don't have to use
multiply operator.
We can only use an operator.
OK, we can only use plus operator or minus operator.
OK, we cannot use the multiply operator.
Now I think we have to solve this problem but I'm not sure.
So if you are multiplying two numbers and the end, can I write it like this.
Basically I am adding the same number and times, ok, I am adding the same number and times.
So we are using one lipless operator here so that the solution to the one solution for this problem
is to just use a loop and that loop will run and times and inside the loop we will add Eminem.
OK.
So I think you can solve it very easily with the help of for a loop of a loop.
But now we have to solve it using recursion.
OK, so with the help of a loop, how you will solve you will keep a variable sum equals zero, you
will run a loop and that group will run and times inside the loop.
What we will do, you will write something like this simplistic to M and when the loop will be already
you will return some.
OK, so with the help of recursion, how we can solve this problem.
So.
We have to calculate Eman Duine.
OK, let's say the value of M is five and let's say the value of industry, so our output will be 15
to a. 15.
OK, so.
And in doing so, can I write Aminta in like.
Multiply and minus one.
Plus M can I write it like this?
Yes, obviously, we can read it like this, this is nothing, but if you multiply inside this and then
minus blessin and these two will cancel out, each others are totally Emman, OK.
And so let's try it and how it will work.
So in doing so, I want to calculate five into three.
What I want to do here is multiply five with two and then add plus five.
So the answer will be five into to that answer will be 15 only.
OK, so basically what we're doing here is so five in total.
This simply means five plus five plus five.
So what we will do.
I will tell recursion to solve this small problem and then I will add five, I will Erdem, OK, this
is M, this is M and this is an OK, so I'm repeating myself.
Let's take one more example, let's say the value of M is three and the value of and is five.
OK, so I want to calculate them in doing so.
Basically what we can do M plus M plus M, how many times.
And Bems.
OK.
So.
I want to multiply three to five.
So I will add three, five times, so three plus three plus three plus three plus three.
OK, so now what we will do, we will use the help of recursion, what we will use.
So what we will do, we will break the problem into smaller problem.
I will tell recursion to solve this part for me.
And that equation will give me the answer and the answer will be 12 and then I will add em.
OK, so this is M so the question will give me the answer, which is well, and then I will add.
And so if I function multiply.
So how does one multiply.
A function will look like it will take to input as argument and then.
What I will call I will call the same function multiply function for the smaller input, so I will tell
you to give me the shut off.
So what it will give me it will give me the answer off and multiply and minus one.
OK, and this is in the end.
And finally, what we will do, we will add after recursion will give me the answer.
I will add this m.
OK, so this will be our formula.
This will be, this will be how that equation will look like.
OK, now first let us write the code and then we will tighten the code.
OK, so what will be our base case.
So the base case will be very simple.
You want to calculate Aminta.
And so this case will be the value of Aniceto.
Then if you multiply with zero then our good will be visit only.
OK, if you multiply any number with zero, the output will be zero only.
So this will be our base case if any zero return zero.
OK, now first let us write the code and then we will try again.
OK.
So the return type will be integer and let's say the name of the function is multiply what it will take,
it will take to integer as argumentum and then.
OK, and what we have to calculate, we have to calculate and doing.
We have to calculate.
And in doing but without using multiply or pretend without for loop or loop.
OK, now there is time for the base case.
So the base case is the smallest problem or solution.
We already know.
So if the value of any zero so any number multiplied with zero will be zero only.
So I will return zero.
Now it's time for the recursive case, what we have to do.
We have to solve the problem for the smaller input.
OK, and what are the smaller and smaller and what is the value of and and minus one?
So.
Smiled and said.
That's my answer is you have to I'm calling the same function.
Multiply.
And I want to calculate and do end minus one.
OK, so at this lane, I have done set off Amerindo and minus one.
And finally, our calculation part, so our calculation part is very simple.
What we have to do.
I will return this my answer.
Plus M.
And NetSol, OK, now let's call this function.
So let's call this function and let us give the value of Immonen.
So multiply.
And have the values are three and five.
OK.
Now, if we learn this code, our output will be 15.
OK?
So let's send the file.
So our output is coming out 15, basically, our goal is working fine.
OK.
So there is a big mistake here.
OK, now let's try to understand how the output is coming out to 15.
OK.
So the values are three in five.
OK, so we have three and we have five.
So these are the values of Immonen.
OK, so five is not close to zero.
So basically, this function will wait at line number 10 and I call the function for Tecoma for.
Again, this will be headline number 10 and I will call for three commentary, similarly, I will call
for three two.
Then I will call for triggermen and then I will call for Tecoma Zero.
So the value of any zero return zero.
OK, so basically this will return zero, so zero will be stored in this Moylan's so small answer becomes
zero.
I guess my answer becomes zero.
Now I am returning small surplus.
And what is the value of my value of a mystery.
OK, so zero plus three that will be three.
So my list of small answers.
This is my answer, then I'm returning small surplus and the value of mystery only.
So three plus three, which is six.
So six is small and also six plus three, which is nine.
OK, so small dancer becomes nine, then nine plus three.
Basically, to so small answer is 12 and then 12 plus three, which is 15, OK, so 15 is our answer.
OK, so that's how that equation is working.
OK, so but you do not have to think all of this, OK.
We will not think I love this, but I will think we will think like first.
Right.
The basic is very simple.
Then write the recursive case.
We will, we are calculating and with about minus one you have to assume, OK, you add line number
10.
What we are trying to do here is we are assuming that this multiplier function works, OK, this multiplier
function, if if you will give to input as argument, it will give me Emmental and minus one.
OK, you have to assume this, OK?
You have to assume that this function will work.
This dysfunction is working, at least give me the small answer I will add plus M to get to get our
prop to get down to what the bigger problem.
OK, and then we are turning our answer.
OK, so first write the code, then think about the diagram.
OK, first write the code and then go to the diagram.
So I hope this problem is clear.
If you have any doubt you can ask me.
OK, thank you.