Thursday, 14 May 2015

Calculating factorial of number(recursive)

Factorial of a Number is as shown below

E.x. 2! = 2*1 ; 3! = 3*2*1 ; 4! = 4*3*2*1 ; 0! = 1

#include<stdio.h>

int fact(int n)
{
   if(n==0) return 1;
   return n*fact(n-1);
   
}
main()
{
   int n;
   
   printf("Enter number to find its factorial : ");
   scanf("%d",&n);
   
   printf("The result is : %d",fact(n));
   
}


No comments:

Post a Comment