Pages

Thursday, March 27, 2014

C Program to find factorial of a number using recursion

/*to find factorial using recursion*/
#include <stdio.h>
#include <stdlib.h>
long factorial (int);
int main()
{
    int n;
    printf("enter the number: ");
    scanf("%d",&n);
    printf("factorial of %d is %ld", n, factorial(n));
    system ("pause");
    return 0;
}
long factorial (int n)
{
    if (n<=1)
        return 1;
    else
        return (n*factorial(n-1));
}

No comments:

Post a Comment