Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Contributor: Ravishankar ChavareRecursion in c Programming
#1
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));
            }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)