Hello, everyone, welcome to this recession.
So in today's session, what we will do, we will try to solve one more problem with the help of regulation.
So the name of the problem is some of that.
It's OK.
Then the problem is some of digits.
So what is the problem?
So the problem is very simple, given the value of let's say it is one, two, three, four and five.
But we have to do we have to add all these numbers.
So the will be 15.
So this is our answer.
OK, so we have to add all the digits of the number and OK to leave the number and is 13 and answer
will be three plus one for if the value of and is equal to plus one which is three.
OK, so I hope you down sort of the value of this five.
The answer will be five.
If the value of and is zero then the answer will be zero.
OK, so what we have to do, we have to add all the digits of the number and OK.
And then we have to return the sum.
OK, so we have already solved this problem addictively using the four will develop.
But now in today's session, since we are learning regression, we will try to solve the same problem
with the help of recursion.
OK, so what resurgency is the answer is?
I will I will come down with a small problem and you do the calculation.
So what you will do.
So we have to find some of the digits of no single digit of the net number.
OK, so what will do?
The case will say.
So what I will do, I will break the problem into smaller part.
OK, I will collocation on this part.
And the question will give me the answer.
So what would answer the question?
Well, give me that answer for all the small problems then, so, you know, the smaller answer, how
you will calculate the bigger answer, which I will do, smaller answer plus the last digit.
OK, so this is last digit.
So smaller surplus, last digit will be our answer.
So 10 plus five, which will be 15.
OK, similarly now how it will work in Benally.
So so this is our number.
OK, let's make the whole cauldron.
So what will happen, I will break the smaller part, I will collocation on this part.
Then this is our number one, two, three, four.
I will call dedication on a smaller project.
Again, I will call it a collision on this smaller part.
Again, I will call the occasion on smaller part.
And again, I will call the occasion on smaller part, so this is zero.
So I'm calling regarding this smaller part.
OK, so I am calling Alabama, so it will be zero.
OK, and the value of and is zero, this is the smallest problem.
So this will become our base case.
So it will return zero.
OK, so, Don, some of the smaller problem is zero, and then we have to add the last minute, so zero
plus one, it will be one.
Now, the answer with a smaller part is one.
We have to work.
The last version, which is two seven plus two is three.
Now, the answer for the smaller part is three, now we have to share the last digit, so three plus
three is six.
Now, the answer for the smaller parties came out to be six.
Now we have to add the last budget, so six plus four, which is 10.
Now, the answer for the smaller part came out to be 10.
Now we have to add the last budget to calculate the bigger problem.
So 10 plus five, it will be 15.
OK, so I hope by now will we know the formula.
So if you want to calculate some of and what we have to do, so some will be a function, it will take
a number and as input and it will give me the sum of the digits.
OK, what I will do, I will give the sum function, the smaller problem.
So this value is.
And by 10.
OK, so this will be what I will do.
I will call, I will call the same function sum and I will give Smolla problem.
I will give number by 10 smaller problem.
So I'm giving this as input.
So some will give me the output for the smaller problem.
And now what we have to do, we have to add the last digit.
OK, so I will add the last digit.
OK, so I'm adding the last digit.
OK, I am writing the last digit now let us write the code and then we will do, then we will try it
again and we will again make the diagram, OK?
So first of all, that they will be in danger, we have to return to some, let's say, the name of
the function someone and what it does, it will take a number as inpart.
And now the base case, so basically it's very simple, the smallest problem or solution we know.
OK, so the value of zero, obviously, the sum will be zero.
OK, so this is our base case.
OK, so this is a case now it's time for the recursive case, OK?
So let's write a recursive case.
So for the recursive case, what will be our small answer?
So our small answer will be very simple, so small answer will be.
Calculate the answer for everything, OK?
And now our calculation part.
So for calculation part, what we have to do, we have to find out the last digit first.
OK, so for calculation, what we have to do.
What is our last digit?
So we're calculating the last budget, I can do something like this and more tonight, so with the help
of this court, I will get the last budget and then what I have to do, I have to return.
Small answer plus last digit.
OK, now let's call this function like let's call the function.
And let us give the relevant two, three, four, five as input.
OK, so what we said our answer will be 15.
OK, so let's let this file.
So our answer is coming out to 15, our gold is working fine.
Let us try to make the diagram again and see what's happening.
OK, so the value of and is one, two, three, four, five, so this is our value, one, two, three,
four and five.
OK, so this is not close to zero, so I will come at this line and I will call for end by 10, so I
will call one, two, three and four.
And this function is waiting in line number 11 dysfunctionally, also be red line number 11, because
it will call one, two, three.
It will wait at line number 11, it will cauldwell, it will wait at line No.11, it will call one and
it will wait at line number 11, it will call zero.
So what will happen?
It will return zero.
So it is returning zero.
OK, so the small answer, small answer is zero.
Then I'm calculating the last digit, which is and more than the value of this one.
So one by 10, that will be one only.
OK, so small and surplused last digit so zero plus one which is one.
So I am returning one.
OK, now here, the value of small answer is one.
OK, so last digit and more 10 SAWTELL more than that will be two.
OK, so the last digit is two.
And then I'm returning the addition of these two.
So to pleasantry, I'm returning three.
Now, the value of small answer is three and then I'm calculating the last digit.
So last digit is 123, more ten.
So last digit is came out with three and then I'm returning the addition of these two.
So three plus three, which is six.
So I'm returning six small answers, six and last digit will be slow and more tense, a lot of it is
this.
This will be our last digit.
So last as it is four.
So six plus four, I'm returning the addition of these two.
So I'm returning then and smile answers 10 and the last digit will be even more tense.
So it will be five.
And then I am returning the addition of these two.
So 10 plus five, which is 15.
OK, so that's how my answer is give out to be 15.
OK, so I hope you have understood the code.
So the code is very simple.
We have to write the base case, then the recursive case.
We have to calculate, we have to call the same function for a smaller input.
OK, and then the calculation part.
OK, so we are writing the code with the help of PMI only.
OK, we are thinking about this diagram later.
First we are thinking about this diagram later first.
We are thinking only in terms of BMI.
We have to think of three steps, Becka's recursive case and the calculation.
OK, if you will write these three steps perfectly, then Nicole will definitely work.
OK, so I hope you understood this problem.
Thank you.