Monday, December 13, 2010

Program to find the factorial of a number using recursive function

#include<stdio.h>

int factorial(int);
int main()
{
    int n;
    printf("Enter the number:");
    scanf("%d",&n);
    printf("The factorial is %d",factorial(n));
    return 0;
}
int factorial(int n)
{
    if(n<=1)
    {
    return 1;
    }
    else
    {
    return n*factorial(n-1);
    }
}

No comments:

Post a Comment