Hey, guys, what's up?
So today we are solving one more problem.
So the drug treatment is very simple.
Given in use, it will give us the value of N and we have to find some of it legit, some of it.
So given given a number and find some of it digit.
For example, if the value of an is my number is let's say.
347 some output should be three plus four plus seven, which is.
Fourteen.
OK.
Similarly to the well, you know, my number is 123 some output, Richard Reid one plus two plus three,
which is six.
Similarly, if the number is one, some output should be.
So my answer should be one.
Similarly, if my number is, let's say ten.
Some output should be one plus zero, which is when if my number is let's say 25, some are, which
would be two plus five, which is seven.
So problem is very easy, given a number and we have to find some of its legit.
OK.
So how we can solve this problem?
If you want to think, if you want to take some time, you can, both of you.
OK.
So the solution is the algorithm for solving this problem is very easy.
So what do we do?
So, for example, my number is three 47.
So first of all, what I will do 347 Modulus 10.
So Waterloo output Remender, which is seven.
OK, then I will divide 347 Biotin, which is thirty four point seven, but in deejayed up on A.J. has
to be in in BIJA, which is 34.
OK, now I will 34, now 34, more than last digit for 34, divided by a ten three point four, which
is three.
Now three more then will give me the last digit, which is three.
Now three divided by ten, which is zero.
Point three, which is zero.
So when we reach zero, stop.
So where did you answer seven plus four plus three.
OK, so this will be my answer.
Seven plus four plus three, which is.
14.
So this is our.
This alone will work.
So what I will do?
Find the last digit.
Find last digit.
How I can find last digit.
No, MAAD, then will you give me the last digit?
You can see here seven was the last digit, four was the last digit.
So if you take.
More to turn off any number.
It will give me the last digit.
So you got the last digit.
What do you will do?
We will maintain a variable sum, which will initially be zero.
And after finding the last digit, we will add the last digit to some because some equals some blis
last.
And now we will not.
And now we are updating the number.
OK.
So number will be updated by number will be divided by 10.
Here you can see 347 was divided by 10.
So my new number is 34.
So with the help of this line, I will get a new number.
So this is new number 34 is new number and 347 was all the number.
Similarly, you can see here, 34 was here, all the number.
And by dividing sorry, the 34 was all in the mood here and dividing by 10.
I will get three, which is my new number.
So with the help of this, I will get a new number.
And how many times I will find the last digit and last digit.
And update a number.
Bill, I get a zero.
Daily, my new number is not close to zero.
So what I will do.
So let me write the code.
So I will do something like this.
Initially, my sum will be zero.
Now, how many times I have to run the loop?
How many times I will find last digit?
Add Lustiger to the same update the number.
How many times daily?
My number.
Is Nathi close to zero Deleware in the mud?
As in articles two zero?
What I will do.
I will find the last digit.
So end let's call it digit, which is number MAAD 10.
So I will get the last digit.
Now, after getting the last digit, I will add this digit to my variable some.
And now we have to update our number.
So number equals number by 10.
And finally.
We will see out some.
So this is all that we have to do.
OK.
So, for example, let's take an example to the Valley of and is 123 OK?
So.
I am writing my output here.
So initially, my variable sum equals zero.
So check the condition is one quantity.
It goes to zero.
No.
The condition is the condition is two.
Number is not close to zero.
You will come inside.
And Bridget did this.
Find out the last digit digit equals three.
Now add this digit.
The way the variable some.
So some will become.
Three.
Now, update the number.
Number equals number by ten.
So a new number equals.
Now check the condition again.
So is will it close to zero?
No.
The condition is to it is not close to zero.
You will come inside the loop.
So any digital clues, no more than that as the last digit digit, it was to add a digit to some.
So some will become three below store, which is five, upbraid the number.
So number will become twelve by ten, which is when I would check the condition again.
So is when articles two zero, the condition is true, you will come inside.
OK.
When is not close to zero, the condition is true.
Yes.
When it's not to close to zero.
Find the last digit, which is one.
Add this digit some.
So some will become.
Here it was five.
So five plus one, which is six.
So somebody becomes six and you have to update the number.
So number equals number about ten, which is one by ten, which is zero.
Now I will check the condition.
So here zero is not close to zero.
This condition is void because zero equals zero.
OK, so this condition is false.
You will come out of the loop of your loop, will terminated and you will print some, which is six
and which is my output.
So let us write the code.
Then I will explain it one more time.
So let us name this file as.
Some of digits.
Not CBP.
Now, what I have to do, I will take a number.
And Bert Fundi use it.
So N10 seen.
And now I will take a variable, some equals zero, which will finally contain the sum of digits.
So while my number is not close to zero, what I have to do, I will find out the last Midgard.
So.
And let's call last.
Digit, which is equal to number.
Maude, 10.
So I got the last budget and I have to add this digit to my variable sum, so some plus it goes to last
digit.
And now I have to update my number.
So number equals number equals number by 10.
And finally, my answer will be stored in variable some.
So I will print out some.
So this is all that we have to do.
OK.
So let us test our program.
Layer to level value of is 123.
So our approach would be six.
No, test it one more time.
Let's see, my number is 10.
So outproduce when.
OK.
One plus you always won some accord is.
Hundred percent.
Correct.
If you're having difficulty in understanding this condition, what you can also do here is you can write
while my number is good than zero because we have to stop when number equals zero.
So the numbers are good, then zero, you will be able to find out the last digit.
OK, so this is also a condition you can also use that a condition if you are not able to understand
previous condition.
So let's say my number is 25, so output is seven.
Now, let us test out.
No, no, no, let us barran our program for any cause, let's say then when it goes down.
So initially, some equals zero.
Now a check is 10 Gurdon's zero.
Yes, the condition is through last digit.
So last digit will be no more than 10.
So 10 more 10, which is zero.
And this last digit to some.
So some equals all the value of some plus lastra digit zero.
Now update the numbers on the medical's number by then.
So number equals all the value of number by ten, which is one.
Now check the condition again.
So one is better than zero.
One is better than zero.
Yes, the condition is true.
You will go inside, find the last four digit.
So last digit a close to one more.
Ten.
Which is when.
And then you have to add this last digit to variable sum.
So some equals all the value of some, which is zero plus last budget, which is one.
So some equals one.
Now you will update the number.
So number equals number by ten, which is one by 10, zero point one, which is zero.
Because in digit upon integer is in Indonesia.
Now you will check the condition again.
So is zero good.
Then Enquist is zero good.
Zero.
No, the condition is false.
Since the condition is false, our loop will terminate.
And I will reach line number 17.
So I will print some.
So my sum is containing one.
And output for this number should be one.
Obviously, this is how our program is working.
Initially, what happened is you will find difficult to understand all of these things.
So how against.
Understand these things.
So the only ways they go to a pen and paper.
Right.
Hold on your own.
Try to understand how things are working.
And with a little more practice, you will be able to chorded yourself.
I will be solving many such problems.
So just to follow my approach.
How I'm approaching these problems.
OK.
So initially, everyone faces difficulty.
I also faced a difficulty when I first see how to find some digits.
OK, so it's completely normal.
If I'm facing difficulty.
So if you have any doubt, feel free to ask.
OK.
Thank you.