Educational Blog: Recursive Function to compute n!

Sunday, 15 February 2015

Recursive Function to compute n!

#include<stdio.h>
#include<conio.h>
long factorial(int);
void main()
{
        int n;
        long fact=1;
        clrscr();
        printf("Enter no ");
        scanf("%d",&n);
        fact=factorial(n);
        printf(" %ld",fact);
        getch();

}
long factorial(int n)
{
        if(n!=1)
        {
                    return n*factorial(n-1);
        }

}

No comments:

Post a Comment