Recursion

Recursion is very useful concept. Recursion, in very simple words, function calling itself. Sometimes, we need to repeat the function many times, for that concept, we have to use Recursion. Let's take an example of Factorial for Recursion. In factorial, we need to go to next number by substracting and perform the same task on it. So, Recursion is used. 

Click Here for Factorial Program using Recursion.

In Recursion, the stack memory is used. We need to break the Recursion condition to make it finite or else, it will run for Infinity times and give will Runtime, as stack memory gets full. So, to make the Recursion condition break, we can use the if else statements. We can write the Breaking condition in if statement and in else condition, the Recursion part is there.

factorial of n (n!) = 1*2*3*4....n

And Breaking Condition for this, can be if(n==0) then return 1; You will get to know about the Recursion in the Factorial Example.
Previous
Next Post »
0 Comment