What is a Recursive function?

Recursion is the process of defining a function which calls itself from within its body. Recursive function is a function which calls itself again and again till the condition which is specified is true. In recursive functions we must give the terminating condition that is the limit upto which a function calls itself otherwise it will become an infinite loop that is a loop that never ends.
Eg of recursion : Program to calculate factorial of a number using recursion
# include
int factorial(int n)
{
if(n <= 1) return 1; else return n*factorial(n - 1); } void main() { int x = 5; printf("factorial of %d is %d",x,factorial(x)); }

More Questions

Leave a Reply

Word Verfication * Time limit is exhausted. Please reload CAPTCHA.