 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can print reverse 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 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 topic, for printing reverse of a number, I have already implemented a code in front of you. I am going to explain this code step by step. You can see two header files stdr.h for printf scanf and second header file math.h for POW function I have included. Then I have declared a function. Function name is reverse. It will receive two arguments as input and it will return an integer. Then inside main function two variables num and result are declared. More two more variables length and temp are declared. Length is initialized with 0. Then printf statement it will print enter an integer number to reverse on console. The enter number by user will be received in num variable using scanf. Then num variable is assigned into temp. So a copy of num is available with temp variable now. Using this y loop, total number of digits which are available in the number is calculated. So this loop calculates number of digits in a number. So here number is assigned into temp. So with the help of temp, number of digits are calculated inside this variable which is named as length. After completion of this loop, this reverse function is called. So this statement is known as function call. Function name is reverse. It is called here. It is passing two arguments. First one is num and second one is length. So num is the original number whose reverse we want to print and length means number of digits which are available in that number and the result will be assigned into this result variable. Using this printf statement, original number and its reverse will be displayed on console. Then main function is terminated. After main definition of reverse is implemented, this block is known as function definition. It is receiving two values first inside num and second inside length variable. Then this if is containing base condition. This base condition is for termination of recursive calling. So in case of recursion, a function definition calls itself. So here function definition is reverse and it is calling itself in this statement. So it is a recursive process for termination of recursion. I have implemented base condition which is length equals to 1. If this condition is true, then return keyword will return a value of num. Otherwise, return will return num modulus 10 multiplied by POW 10 comma length minus 1. So this is an expression. Its result will be stored inside stack and then further recursive calling of reverse will be performed. If this base condition is false, then this recursion will take place. If this if condition is true, then recursion will be terminated and the result will be returned into this result variable and that will be displayed on console. So this is the technical explanation of this program. First I am executing this code so that we can check the result. Then I will take an example and then I will be explaining each step how that result will be calculated using this recursive calling. So I am executing this code. I am entering 1, 2, 3, 4 and I am pressing enter key. You can see output the reverse of 1, 2, 3, 4 is 4, 3, 2, 1. So it means our code is working properly. It is printing correct results. Now I am taking the example. Suppose num is 1, 2, 3. So temp will be 1, 2, 3. Here with the help of this loop, number of digits are calculated. So each time length is incremented by 1 and temp is divided by 10. So this loop will repeat 3 times. So the value of length variable will be 3 and after completion of loop, value of temp becomes 0. Then this reverse function is called it is passing num and length into num and length. So variable length is also containing 3 now. Now we have to focus on this definition only. So first we have to check this base condition. It is false. So this return statement is calculated. In this return statement, first this expression will be performed. So num modulus 10 right now num is 123. 123 modulus 10 means 3. Then multiplication POW 10 comma length minus 1. So POW 10 comma length minus 1. So 3 minus 1 is 2. So it becomes POW 10 comma 2. So 10 raise to 2. So it means we have to multiply 10 by 10. So we can write 3 into 100 because 10 into 10 is equals to 100. So this 3 into 100 will be stored inside stack and then this reverse will be called again for next recursive process. Here num upon 10 and minus minus length is passed. So num upon 10 num is 123. So 123 upon 10 it means 12 will be passed inside this num variable and length will be decremented by 1. So it becomes 2 and it will be passed into this land. So right now land is 2 and num is 12. Again base condition is false. So this expression will be calculated. Here num modulus 10. So num is 12. 12 modulus 10 means 2. So this time 2 into land is 2. So 2 minus 1 is 1. So POW 10 comma 1 it means value will remain 10 and then plus sign because here plus is available. So after calculation of this expression the result will be stored inside stack and next recursive process will be performed. So here recursive function call will take place. So num is 12 12 by 10. It means 1 will be passed into num. So num is now 2. Sorry 1 and length will be decremented by 1. So it will become 1. Now base condition is true. Length W equals to 1. So it will return num. Num is 1. So it will be stored inside stack. Now recursive process has been terminated and these values are available inside stack which we have to calculate. So if we calculate it 300 plus 20 plus 1. So the final result will be 321. So this way this recursive process has calculated reverse of a number which is entered by the user. I hope you have understood the concept how you can calculate reverse of a number using recursive in C. If you want to watch more programming related videos you can subscribe my YouTube channel. Thank you for watching this video.