Hello, everyone, welcome to this session.
So in this session, what we will do so we will try to solve one more problem with the help of commission.
So the name of the problem is the numbers.
OK, so we will record this problem.
We will solve this problem with the help of the commission.
So what these problems suggest, so if the value of these five, what would I have to do?
So I have to print the numbers from one to end.
So if the value of minus five, I will print the number one, two, three, four, five.
If the value of and three, I will print the numbers.
One, two, three.
OK, so what I have to do, I have to write a function print and and this print and function.
What it will do, it will print the number, it will start printing from one billion.
OK, so this is the work of this function.
We can solve this problem very easily using default all the way, but we have to solve this problem
using.
So using irrigation, what I have to do if I want to solve the problem for and then I have to solve
the problem for the smaller end.
OK, so what this printing function will do, so this printing function, it will print the number from
one to end.
OK, so this printing function, it will print the numbers from one, two and.
So can I write like this?
So what this print and minus one function will do so print and function, its job is to print the numbers
starting from one then.
What this sprint and minus one will do, so it will start printing the number from one bill and minus
one.
OK, and this is our goal.
And this, this and this will be put off and minus one function, then after printing, then minus one
we will print and OK after printing and minus one we will print another term.
So unless we also get printed.
So these two will become equal.
OK.
So this will be our recursive case.
Simple enough.
OK, so let's write the code for this.
So first of all, word of the return type return will be void because I'm not I'm not returning anything.
I'm basically printing, OK, so I have to print what it will take.
It will take on this argument.
OK, so first of all, what will be the best case?
Whatever the best case, so basically the smallest the smallest problem whose solution we already know.
So the smallest problem will be if the value of any zero, so if the value of any zero, what I have
to do, what I have to print, I do not have to print anything, OK, if the value of Aniceto do not
print anything.
So this will be our best case because I have to start printing from one you can see here.
We have to start printing from one.
If the value of an is zero, we will not print painting.
OK, I have to start printing from one.
You can also write the best case for an equals one.
Also, if the value of this one, then print one.
OK, so as you wish you can as a wish, you can modify the Good Samaritan type word.
Hence I am not understanding anything.
OK.
So if the value of any zero then do not print anything otherwise.
First, what do you have to do.
Recursive case.
So recursive case will be.
So dysfunction, brain function, it brings the number from one to and now I'm calling this brain function
four and minus one, what will happen?
Our numbers will get brain dead from one twin.
So what will the output of this line?
This line will print the numbers starting from one.
And minus one.
OK, so this is the this is our output in line number 11.
OK, so this is our output line number 11.
Now our third thing.
So the calculation part, what I have to do, I have to print and it's done.
OK, now let's print.
OK, so this is our output.
OK, so this print function, what it what it does is it brings the number from one twin print, then
minus one, it will print the number from one to ten, minus one.
And then I am printing the net number.
OK, now let's call this function, let's call this print function.
Four to five.
OK.
Now, let's than another file, OK, so dysfunctional, not returning anything, so I have to call this
function, I cannot write you out, OK, because dysfunctional, not running anything.
Now let's an our file.
So this is our output one, two, three, four and five.
OK, so our goal is working fine.
Now after writing the code, what we have to do, we have to make their diagram.
We have to tighten our code so we can understand it better.
OK, so Brent five, the value of and is five.
OK, so this is five.
So I am writing the output here.
I will write the output here.
OK, so five will call on four.
Four will call on three.
Three will call on two, two will call on when, one will call on zero.
So if the value of any zero, what I'm doing is done.
So I will come here.
We're done.
OK, so one was waiting at line number 11 when was waiting in line number 11.
Now I will reach your line, but I didn't see out and OK, so at this line what will happen to out end.
So when will get printed.
Now you can write a written statement here also.
OK, they're done the statement.
This is optional.
So what will happen.
I will come here.
OK, so the value of this to so, too, was also waiting at line number 11, then CO2, so too will
get printed.
So one gets printed first, then two printed, then are done.
I will write the line written, I will write the statement written.
But this is optional.
Okay, because the cord and red line number 15.
So writing written is optional here.
So the value of industry now will get better.
So return the value of this for for will get printed the value of faintness five, five years, get
printed and then finally return, I will reach the mean and then return.
Our program will be over and this will be our output.
OK, so you might so you might have confusion.
So I am returning.
I am writing right down here, ok.
It will not affect our goal of course will still work fine.
So our output is still one, two, three, four, five.
OK, so our goal is working fine now.
One more thing.
So here.
I have been the numbers in ascending order.
I am printing the numbers in ascending order one, two.
Now, whatever, I want to print the number in descending order, for example, of the value of and
his wife, I want to print five, four, three, two and one.
OK, this is how I want to print the number.
Basically, I want to print the number in descending order.
OK, so what we will do let's say I am writing print to function, so print to what it will take, it
will take and as input and its work is what it will do, it will print the numbers in descending order.
Five, four, three, two and one.
OK, so first of all, what I will do, I will print and OK, because the value of it is five five is
getting printed first.
So first of all, I will print that number in and then I will call the function and minus one.
So what.
And minus one will do so and minus one will start bending the numbers from and minus one then and minus
two L1.
OK, and first of all and we'll get printer and our work was also the same.
We have to print the numbers in descending order.
OK, so first I have to print N and then I will call, I will call the same function here.
It will be a portrait of this.
So first I was calling and minus one and then I was printing and but here first I will print N and then
I will call and minus one.
OK, so basically descending order will be the opposite of the ascending order.
OK, so what I will do, let's write print to function.
Let us copy this code.
So this is Sprink to function now what I have to do, I have to just change the order of these two lines.
So first, I will print an.
OK, so this will be our bench to function, so to function, what it does is.
So this is our best case now.
First I will print and and then I will call and minus one.
So sorry, this will be print to OK, print to function.
So what this function will do.
It will start printing the numbers from and minus one.
Well, one, OK, so this will be the output of this line, but before the output of this line, I am
printing and OK, now let's call print to function.
So I'm calling print to function and I'm giving fifers input.
So our output will be five, four, three, two and one.
OK, so let's another good.
So I put five, four, three, two and one now after writing the code, what we have to do, we have
to have a goal so that we can understand what is going on here.
OK, so the value of N is five.
OK, so this is five and I will write my output here.
OK, so five is not close to zero C out and so five will get printed and then I am calling print to
function with the value and minus one.
OK, so the value of Anisfield four is not close to zero zero then.
So four will get printed then.
We are calling with a smaller function.
OK, I will call on three.
Then they will get printed, I will call and one I will call and do two is not close to zero, then
I will bring it to.
Then will call on one.
So one is not close to zero, so I will bring one, then I will call on zero zero zero equals zero.
Then I what I will do, I will return.
So I will return.
So when was waiting at line number 26.
OK, this one was waiting at line number 26 then written, so written there was also waiting at line
number 26 and then return.
So I will return three was waiting in line number 26 then it will return four was also waiting.
I remember 26 then written and then five was also waiting at line number twenty six and then return.
So it had done so and this is our output.
Five, four, three, two, one.
OK, so I hope you understand the code, how it is working.
OK, so writing this return but writing this written statement is optional here.
If you want you can remove it also.
OK, for example let's remove this line and then also have a code of a code will work because the function
ends here and there, the function and that automatically means that are done OK with the void you have
option to return.
This is optional here, but writing return here is mandatory.
OK, writing the return statement inside the IF is mandatory.
OK, so this return is compulsory.
Otherwise, what will happen if I will not write the written statement, what will happen, I will commit
line number 22, which is wrong.
OK, so writing written is mandatory here.
But this return is optional.
OK?
And also, this return is optional.
Now, I doubt this are done, but now if we run our program, our program will still work fine out probably
five, four, three, two, one, one.
OK, so I hope you understand why this is mandatory.
I am.
Let's try to.
So it was a value of industry.
Let's say I am calling brain to function for the value of industry.
So three, what will happen.
Three will call on, two do will call and one no one will call on zero zero zero equals zero.
So if you will not read the written statement, what will happen.
So zero will come here.
Zero zero zero zero will get.
This is our output.
So what will happen.
Zero will get printed.
OK, so this is Brent to function.
So what will happen to our output is three to one.
Now what will happen?
The value of N is zero, so zero zero.
But if the written statement is not here, then what will happen?
I will come line number 23.
So zero will get printed.
Then what I will do, I will call on Ben to function and mightiness.
And so it will call on minus one, then minus one will get printed, it will call on minus two, it
will call on minus three and so on.
Basically infinite loop problem will be there.
OK, so infinite loop problem will be there.
That's why this return is mandatory here.
If this are done, is there what will happen.
I will return from zero.
OK, and this will not happen.
OK, so this return is mandatory and there is this written is optional.
OK.
And similarly for this one, also for brain function.
OK, what will happen?
Suppose the value of industry.
Now, what will happen and is not close to zero, this this is our output.
I'm calling on smaller part.
So to do will call on when one will call on zero.
OK, so zero zero.
So if the written statement is there, what will happen?
I will come out one and then one will get printed.
But if this written statement is not there, what will happen?
What will happen when I call on zero zero zero but the written statement is not there, then I will
come here a headline number 11.
I will call minus one, then minus and will call on minus two.
Minus two will call on minus three.
Ansun, basically infinite loop problem will be there.
That's why I return is mandatory here.
OK, inside the base case returns statement is mandatory.
OK, remember this thing.
So I hope you understood the school.
OK, thank you.