 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can calculate factorial of a number using recursion in C. Before starting, you can subscribe my YouTube channel by clicking on the link which is available at bottom right corner of this video. You can download my app Techimage that is available on Google Play. You can connect with me by following these details which are available in front of you. Now coming onto the topic, I am using Dave C++ IDE for implementation of this code which will calculate factorial using recursion. For that purpose, I am first including a header file that is stdio.h. It contains declarations of printf and scanner functions that I am going to use. Then before writing main function, I am going to declare a function that is factorial. So declaration is int, fact int. This is function declaration. After this declaration, I am defining definition of main. Inside this main function, I am declaring two variables n and f. Then I am using printf. Inside printf, I am typing a message and enter a number which will be displayed on console screen while I will be executing this code. For reading purpose, I am using scanf %d and %n. So using this printf and scanf, I am reading a number from user. Now I am calling fact function using this statement f equals to fact of n. This is function call. The return value which is received by f will be displayed with the help of this printf. This is complete definition of main. After this implementation, I am going to implement definition of fact function. This is a recursive function. That's why I don't have to use loop. First of all, I have to implement a base condition. Friends, remember whenever you want to implement recursion, you have to implement a base condition which will be responsible for termination of function calls. So recursion says you can call a function by itself. So here in this function definition, factorial function definition, I will be calling this function repetitively with the help of recursion. So for termination, I am implementing this base condition which is n equals to 0. If it is true, then it will return 1. Otherwise, it will return n into factorial of n minus 1. So friends, with if I have implemented base condition, this is base condition and inside else this fact of n minus 1, this is recursive call. In this calling, n is multiplied by fact of n minus 1. So friends, suppose here inside main function where function call is available, if I am passing value of n is 3, this n which is formal parameter will receive 3. Then condition will be checked. It is false. Then else part will throw return n into factorial of n minus 1. So it becomes 3 into factorial of 2. So you can understand it by this. It becomes 3 into factorial of 2. So here this factorial of 2 is again a function call. It is calling itself. So that's why here n becomes 2. Then next time calling will be 2 into factorial of 1. Then this n will receive 1. Condition is false. Again it will be called. Next time calling will be 1 into factorial of 0. When n will be receiving 0, this base condition will become true. It will return 1. So these 3 into 2 into n 1 into these values will be stored inside stack. When base condition will achieve all these values will be multiplied and the result will be returned into this f variable which is available in main function at function call statement and then value of f will be displayed on console. So friends with the help of this demonstration I hope you have understood how you can implement factorial program using recursion. Now I am saving this code first. It is saved. Now first I am compiling it. Errors and warnings are 0. So we can execute it. It is asking for a number. I am entering 5. You can see the output factorial equals to 120 is displayed on console. So friends with the help of this demonstration I hope you have understood how you can implement factorial using recursion. This is a simple demonstration which is calculating factorial in C program with the help of recursion. And you have to remember that while we are implementing recursion we don't have to implement loops to implement the programs and you have to make all the programs with the help of functions. And function contains 3 parts. I have implemented all 3 parts. It is function declaration at line number 2. Line number 8 is function call and from line number 11 to line number 17 this is known as function definition which is containing 2 parts. First is base condition and second one is recursive call of fact function. So this is all about how to calculate factorial using recursion in C. If you want to watch more programming related videos you can follow my YouTube channel. You can subscribe it. Thank you for watching this video.