00:04
So in this question we have been asked to write a recursive program to find out the sum of the digits of an integer.
00:15
So for example, there is an integer 912.
00:21
So the sum of this would be 9 plus 1 plus 2, which is 12.
00:26
So if we input this number, we should get this output.
00:29
That's what we have to do and we have to use recursion.
00:32
We cannot use 4 loop.
00:33
And this could be any length of the integer.
00:38
So, in a very simple way, recursion basically means that you call the function within a function, so that you can avoid for loop.
00:48
But the important thing is that you must also have a reference break point for the function.
00:53
Because beyond one point, the function has to come to an end.
00:57
Otherwise, a recursion, if you call a function within a function, it can keep running forever.
01:01
So these are the two things that you have to keep in mind.
01:02
So the first thing that we need to find out is, in this case, is to figure out what is the operation that is repeating.
01:13
So i said we can do it in recursive fashion.
01:16
So if we have to take a number, let's just take this example that we have right now.
01:20
So 9 -1 -2 is the example.
01:23
So if we go about doing this, we would like to separate two first, take it out, then separate one first and add it to this and then separate the last nine and then add it again to it so that we go back.
01:34
Get a total of 12.
01:35
So the operation that we have that is repeating is separation and addition, separation and addition and finally addition.
01:45
So separation and addition is the repeating process and the final process is only of addition.
01:51
So this will give us the final condition.
01:55
So what we have written a program here.
01:57
So the main function is here in the main and what we do is we ask the user to input a number using the input option and we know that this option whenever we'll wait for the input of a user and but store it in a string format so we use the eval function in the next line to evaluate this to give us a number if there's a number in the string so that what converts the string into an integer and then we simply print out the sum of the digits using our function some digits.
02:39
So how the sum digit function works? let's look at that.
02:42
The function is over here in this portion.
02:45
So it takes in the x or the number at any given point.
02:52
And what by that what we mean is that if we take go back to the example and take the process...