Recursive functions

Recursion

Firstly, What is nested function:
When a function invoke another function then it is called nested function.
But,
When a function invokes itself then it is called recursion.
NOTE: In recursion, we must include a terminating condition so that it won't execute to infinite time.

Example: program based upon recursion:



#include<stdio.h>
#include<conio.h>
void main()
{
int n,f;
int fact(int)
printf("Enter a no.");
scanf("%d",&n);
f=fact(n);
printf("The factorial of a no. is:=%d",f);
}
int fact(int n)
int f=1;
{
 if(n=0)
return(f);
else
return(n*fact(n-1));
}


Previous Page                                                                                       Next Page

Spread the word! By sharing this Post!

Pageviews This Week