 Hello, welcome to the session recursion in that factorial example. At the end of this session the student will be able to implement program to find factorial of a number by using recursion as well as iterative method in C. Basically what is the factorial? The factorial function the symbol it is indicating says to whatever the number has chosen for factorial it has to be multiplied up to the 1. So, if it is 1 it will be 1 only 2 then 2 into 1 up to 1 it will be 2, 3 into 2 into 1 it will be 6, 4 into 3 into 2 into 1 it will be 24 like this. Whatever the number is there that has to be multiplied up to the last one sequence and whatever the answer will be there we have to calculate. Now here calculating from the previous value if we are having a previous value we can easily calculate the factorial from the previous one. So, if we are having 5 and if we are knowing the value that 4 factorial is 24 then 24 into 5 we can get 120. And if we want to calculate fourth term and we are knowing the previous term is having value 6. So, 6 into 4 we can get the 24 like this whatever the number if we are knowing the whatever the previous factorial number then it is easily can be calculated. See what is the application or use of this factorial we can do this one of the example it is shown here. If one letter is A is there then there is only one way to represent that one. If we are having A and B the representation will be into 2 way that we can represent it at as AB or BA. And if we are having 3 letters ABC then we can represent into 1 into 2 into 3 way that is a 6 way. So, here it is shown that possibilities ABC, ACB, CAB, BAC that placement of every character is changed in this case. So, if we are knowing the factorial so, we can give the all the possibilities of that particular characters how many type it can be present ok. If nothing is there so, only one possibility that nothing we can replace it or we can place it. So, you can try this if as we have seen up to this here we are having 4 letters. So, how many possibilities can be represented with this 4 letters was for some time and you can represent without repeating anything ok. Here is the answer so, we are having the 4 characters so, 4 into 3 into 2 into 1 that is the 24 way we can represent all this ABCD ok. Now what is the factorial and how we are calculating that that is one more possibility here we can see that the 5 it is having the final value is 120. Now we have seen that if we are knowing this 4 factorial then we can directly multiply. So, 4 factorial can depend upon the 3 factorial, 3 factorial can depend upon the 2 factorial and 2 factorial can depend upon the 1 factorial. Now 1 is having this answer 1 so, it will be replaced by 1 into 2 then that will be 2, 2 into 3 like this we can replace that values of that particular factorial both programs first for the iteration and then we will go for the recursion. So, in the iteration we are using the loop here we are having the number so, here factorial number 5 we are calling for that so, here integer 5 will be there then if it is check that it is 1 no then it will go for the next calculation of the factorial. So, here it will go 2 in up till 5 the loop will be running so, fact will be there it is already 1 and factorial into the count ok. So, here count is now 2 1 into 2 again next 2 is equal to 2 into 3 next like this the factorial will be calculated of 5 it will be 120. So, this is the simple way of the iteration, but here we need fact count we have to maintain that variables also then we will see how it can be called the recursion just we have seen instead of phi u is equal to phi into 4 into 3 into 2 into 1 here we are replacing it by phi u into 4 factorial. So, like this this can be cut down into the simple calculation function and then that simple last one will be answering the answer and then it will be passed to the next step. So, this analysis is there n into n minus 1 into n minus 2 that is replaced by this recursion ok. So, we will see how it is possible to do this simple case answer is that is the smallest answer simple answer that is 1 this is the recursion just which number we are calling that will be called this. So, here it is passing if it is less than or equal to 1 we will return 1 otherwise we are calling this factorial again and again the value should be acted is 24 and how it is done we will see first phi u factorial it will be calling so this is the function if it is equal to 1 it will be returning 1 else it will be going for phi u into factorial phi u minus 1 then whatever the value is there it will be returned there. So, here what will happen before returning this value it will call phi u into factorial phi u minus 1 means it will call factorial 4 ok in the factorial 4 it will check is it a 1 no then again it will call 4 minus 1 that is 3 again it will check if it is a 1 no then it will be calling the factorial of 3. So, here in the factorial after factorial 3 it will be factorial calling 2 again 2 is not the smallest or it is not the termination. So, it will call 2 minus 1 that is factorial 1 now here 1 is equal to 1. So, it will return the value 1 1 into the factorial value here only it will be terminated it will be returning the value 1. So, that 1 value will be returned to this factorial 2 as we are having 1 into 2. So, that is 2 then this 2 value will be returned to this factorial 3 minus 1 it will be 3 into 2 is 6 those 6 is returning to this factorial 4 minus 1. So, it will be calculating 4 into 6 that will be 24 and 24 is passed to this function then it will be 24 into 5 that will be giving the value 1 2. So, without using any other variable it can be recall that and as we are putting all this value this calling on the stack as we have seen everyone whatever this value is pushed on the stack again it will pushed and when it is 1 it will be popped and next it will be passed it will be again popped 2 then it will be popped 6 as they are returning the values. So, this is the reference. Thank you.