 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can add all odd numbers between 1 to N using recursion in C. Before starting, you can subscribe my YouTube channel by clicking on the link which is available at the bottom right corner of this video. You can download my app Techimus 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 implementation, I am using Dave C++ for program implementation. First statement is header file inclusion. I am including stdio.h for that purpose. Then I am declaring a function sum. This statement is function declaration. This function will receive an integer as input and it will return an integer as output. Then I am implementing main function definition. Inside main, I have declared two variables N and S. Then I am using printf statement and messages enter value of N. This message will be displayed on console. Then the entered value is received by scanf inside N variable. Now I am calling some function and input N is passed inside it. This statement is known as function call. The return value which is available inside S will be displayed on console using this printf statement. This is complete implementation of main. Now I am going to implement definition of sum function. This is function definition. This function will be a recursive function. So here I have to define two properties of recursion. First one is base condition. Base condition is responsible for termination of recursion. And second one is recursive function call. So first I am implementing base condition. That is N equals to 1. If this condition is true, then 1 will be returned. Otherwise return N plus sum of N minus 2. This function will be called again. Here this is base condition and at last return statement is containing recursive function call. This is recursive function call sum N minus 2. And you have to remember that whenever you will be executing this code, you have to enter odd number only as N. So starting from 1 to that odd number, all the odd numbers which are available in between them will be added through this program implementation. So here suppose initial value of N is 7, which is received by this formal parameter N. So 7 is not equals to 1. So base condition is false first time. So return statement will be converted into 7 plus sum of 5. So next time sum of 5 will be called and this 7 plus will be stored inside stack. So suppose 7 plus is stored inside stack and next function calling will be like this 5 plus sum of 3. So sum of 3 will again call this function definition and 5 plus will be stored inside stack. Next time 3 plus sum of 1 will be called. So 3 plus will be stored inside stack and sum of 1 will be called. And this function will be executed and then this base condition will be checked. Right now it is true. So it will return 1. So base condition has stopped recursive function call a process. So 7 plus 5 plus 3 plus 1, all these values are stored inside stack. So 1 plus 3 plus 5 plus 7 will be added and the result will be stored inside the S variable, which is available inside main and which is calling some function and the result sorry here I have to use S. So with the help of this S output will be stored or you can say display on console screen. So I hope you have understood how we can add all odd numbers which are available between 1 to n using this demonstration. Now I am going to compile and execute this code. I am entering 7 it is displaying 16. So suppose we add 1 plus 3 so result will be 4 then we have to add 4 into 5. So result will be 9 and then we have to add 7 into 9. So 9 plus 7 is 16. So you can see that this output is correct. This program is adding all the odd numbers which are available between 1 to n and you have to remember that the n must be an odd number. So implement this code at your own so that you can understand how you can add all the odd numbers between 1 to n using recursion in C. If you want to watch more programming related videos you can connect or you can subscribe my YouTube channel. Thank you for watching this video.