Pro-Tutr
Recursion in c Programming - Printable Version

+- Pro-Tutr (http://protutr.com)
+-- Forum: Basic Programming Languages (http://protutr.com/forumdisplay.php?fid=23)
+--- Forum: C (http://protutr.com/forumdisplay.php?fid=21)
+--- Thread: Recursion in c Programming (/showthread.php?tid=332)



Recursion in c Programming - Ravishankar Chavare - 01-06-2018

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));
            }
}