-->

Facebook

Jasper Roberts - Blog

Tuesday, April 14, 2015

A C Program to find out factorial of a given number using recursion.

#include<conio.h>
#include<stdio.h>
int fact(int p);

void main()
{
            int n, ans;
            clrscr();

            printf(“Enter the number:”);
            scanf(“%d”,&n);

            ans = fact(n);

            printf(“Factorial of  a given number %d is %d”,n,ans);
            getch();
}
int fact(int p)
{
            if(p==1)
            {
            return 1;
            }
            else
            {
            return p*fact(p-1);
            }
}

OUTPUT:
Enter the number: 3
Factorial of  a given number 3 is 6