Tuesday, October 20, 2015

Recursion in C programming language



                Hey guys! In the last post, I mentioned about advantages of using function in C programming language. The one of the advantages of using function is function can call itself, we can call it recursive. Now, I will explain more about recursive function or recursion. Recursion is a process of the function who call itself again and again. But, when using recursion, we need to be careful when define the exit condition from the function or it will be in infinite loop. Recursion are very useful to solve the mathematic problems. Here are some example of solving mathematics problems using recursion.
Number Factorial
Here is the example of recursion in solving number factorial.
And here is the output. First, you type the number that you will find its factorial, then click enter. In this example, I am using the number 5.


Fibonacci Series
Here is the example of recursion in solving fibonacci series.
And here is the output. It will show fibonacci series like this picture below.

Find the power of the number
Here is the example of recursion in finding the power of the number.
And here is the output. First, input the number then, input the number of the power. And it will show the result like this picture below.

Actually, there are so many example of recursion. I just explain three examples, and you can find out the other examples by yourself, guys! You can find it from http://www.cquestions.com/2011/08/example-of-recursion-in-c-programming.html or http://www.cs.utah.edu/~germain/PPS/Topics/recursion.html .
The advantages of recursion are avoid unnecessary function in making a program, it makes the code size smaller. The disadvantages of recursion are it makes the code confused, really logical, and takes a lot of stack spaces.
That’s all about RECURSION from me. Don’t forget to try it by yourself! Like usually, have a great time with coding, guys! ^^



No comments:

Post a Comment