Saturday, 30 December 2017

C program to find factorial of a given number using recursion

#include<stdio.h>
int fac(int n);
int main( )
{
     int n, fact;
    
     printf("Enter a number");
     scanf("%d",&n);

     fact=fac(n);


     printf("Factorial of number %d is %d", n, fact);


  return 0;

}

int fac(int n)

{
     if(n==0 || n==1)
         return 1;
   
     else
          return(n*fac(n-1));
}



No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...