Wednesday, 26 March 2014

Write a recursive function to compute factorial of a number.

#include<stdio.h>

int factorial(int n)
{
    if(n<=1)
        return 1;
    else
        return n*factorial(n-1);   
}
main()
{
    int a,b;
    printf("\nEnter a number=");
    scanf("%d",&a);
    printf("\nfactorial %d is %d ",a,factorial(a));
}

No comments:

Post a Comment