Sunday, February 24, 2013

Find Factorial of number using recursion in C

#include<stdio.h>
int factorial(int n)
{
    if(n == 0 || n == 1)
         return 1;
    else
        return n*factorial(n-1);

int main(void)
{
   int n;
   printf("Enter Number to Find Factorial : ");
   scanf("%d", &n);
   printf("Factorial of %d is %d",n,factorial(n));
}


Sample Input and Output:-

Enter Number to Find Factorial : 5
Factorial of 5 is 120


This program works fine to find factorial upto 13. Although thts very small number. To find out factorial of some bigger numbers, keep updated. Will be uploaded soon.



0 comments:

Post a Comment