Recursive functions are those functions, which call itself within that function. A recursive function must have the following type of statements.
- A statement to test and determine whether the function is calling itself again.
- A statement that calls the function itself and must be argument.
- A conditional statement (if-else)
- A return statement.
C – FACTORIAL NUMBER EXAMPLE PROGRAM :
This is the most famous program on recursion. Many versions of this program are available. All programs differ only in checking conditions. I prefer to write like the following one.
long int fact(int x)
long int f;
printf(“Enter a number \n”);
printf(“Factorial of %d is %id ”,n,fact(n));
|Enter a number
Factorial of 5 is 120