 Hello friends, I am Sanjay Gupta. In this video I am going to demonstrate you how you can calculate some of the even numbers 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 Takimiz that is available on Google Play. You can connect with me by following these details which are available in front of you. Now coming on to the topic. I am going to implement a code which will add all even numbers using recursion in C for typing or implementation of the program. I am using Dave C++ software. First of all, I am including a header file that is stdio.h. It is for printf and scanf predefined functions. Then I am declaring a function sum. This statement is function declaration that I will be defining after implementation of main. Now I am implementing main function which will call some function for execution. Inside this function I am declaring two variables and an S. Then printf it will display the message and the value of n on console. To receive the input, I am using scanf statement which is containing % as format specifier and then variable n which will receive the input entered by the user. Now I am calling the function sum and I am passing n as an argument. This statement is function call. The result which will be returned back will be stored inside S. So I am printing that result with the help of this printf function. This is complete implementation of main function. Now I am implementing some function definition. This is function definition and this function definition is recursive function definition which will not be using any kind of loop. Whenever you want to implement any recursive function, you have to implement two states. First one is base condition and second one is recursive calling. For base condition I am using f condition and condition is n double equals to 0. Whenever value of n is 0, then this base condition will return 0. If this base condition is false, then return statement will return n plus sum of n minus 2. This if condition is known as base condition and this return statement is recursive function call. So friends, this is complete implementation of the program which will add sum sorry which will implement or which will print sum of all the even numbers. For example, I am taking a number 8 which will be provided by this function call. So initial value of n is 8 that will be received by this function definition. Then this base condition is false because n is not equals to 0. Then as statement will return n plus sum n minus 2. So you can understand it by this 8 plus sum of 6. The function call will convert into this statement, this function call. 8 plus sum of 6. So sum of 6 will again call this function definition. This is a recursive process. Function calling is calling its function definition itself. So next you can write it like this. 6 plus sum of 4. Then again sum of 4 will become function call. So this will convert into 4 plus sum of 2. Then 2 plus sum of 0 will be called. While sum of 0 will be called, this base condition will become true and it will return 0. So here whenever we are calling a function, the remaining parameters that are 8 plus 6 plus 4 plus n 2 plus these values are automatically stored inside the stack. At last, 0 will be returned. So that will be also stored inside stack. Then after termination of this recursive calling, these all statements or these all values will be added that are available inside the stack and the result will be returned back to the main function calling statement. So main function calling statement is this, which is calling some function. So initial value is provided by this n and the resultant value will be received by this s variable that will be displayed back on console using printf. So friends, with the help of this example, we can print sum of all even numbers on console. Now I am going to execute this code. So I am compiling and executing this. It is asking a number. So I am entering 10. It is displaying sum equals to 30. So friends, all the even numbers which are available in between 1 to 10 are added. So it is printing sum of 2, 4, 6, 8 and 10 that is equals to 30. So friends, with the help of this simple example, I hope you have understood how you can add all the even numbers which are available between 1 to n. This program is implemented with the help of recursion c and it is also implementing user defined functions. So implement this code at your own so that you can understand this concept well. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.