01-06-2018, 01:45 AM

Recursion

When Function is call within same function is called Recursion.

The function which call same function is called recursive function.

Simple examples

There are two type of recursion normally

1.normal recursion

2.tail recursion

Advantages

-be maintained by recursion.

-Stack evaluation will be take place by using recursion.

-In fix prefix, post-fix notation will be evaluated by using recursion.

Disadvantage:

-It is a very slow process due to stack overlapping.

-Recursive programs can create stack overflow.

-Recursive functions can create as loops.

Simple program to find out factorial of given number using recursion

When Function is call within same function is called Recursion.

The function which call same function is called recursive function.

Simple examples

Code:

`Function(){`

Function();

}

There are two type of recursion normally

1.normal recursion

2.tail recursion

Advantages

-be maintained by recursion.

-Stack evaluation will be take place by using recursion.

-In fix prefix, post-fix notation will be evaluated by using recursion.

Disadvantage:

-It is a very slow process due to stack overlapping.

-Recursive programs can create stack overflow.

-Recursive functions can create as loops.

Simple program to find out factorial of given number using recursion

Code:

`#include<stdio.h> `

int main() {

int fact(int);

int i,f,num;

printf("Enter any number: "); scanf("%d",&num);

f=fact(num);

printf("Factorial: %d",f);

getch();

}

int fact(int n) {

if(a<0)

return(-1);

if(a==0)

return(1);

else {

return(n*fact(n-1));

}

}