Recursion function

Recursion function is a function that call itself up to the certain number of times or till the condition is not satisfied. In recursion function we cannot use any loop only if condition is used.

Example 1: WAP to find factorial using recursion function.

#include<stdio.h>
#include<conio.h>

int fact( int n );

int main()
{
    int n, r;
    printf("Enter number: ");
    scanf("%d",&n);
    r = fact(n); //function call
    printf("Factorial = %d",r);
    getch();
}

int fact(int n)
{
    static int a;
    if(n==1)
        return 1;
    else
        a = n * fact(n-1);
    return a;
}
Enter number: 5
Factorial = 120.