Featured Post

Wednesday, November 2, 2016

C program to find Factorial of a given number using recursive and non recursive functions


/* C program to find the factorial of a given number using non recursive functions */

int factorial(int);
void main()
{
   int n,result;
   printf("\n enter any number");
   scanf("%d",&n);
   result=factorial(n);
   printf("\n factorial of a given number %d is %d",n,result);
}
int factorial(int m)
{
   int i=0,fact=1;
   for(i=0;i<m;i++)
   fact=fact*i;
   return fact;
}

OUTPUT:
     Enter any number
      4
     factorial of given number 4 is 12




/* C program to find the factorial of a given number using recursive functions */

int factorial(int);
void main()
{
   int n,result;
   printf("\n enter any number");
   scanf("%d",&n);
   result=factorial(n);
   printf("\n factorial of a given number %d is %d",n,result);
}
int factorial(int m)
{
   if(m>=1)
   return m*factorial(m-1);
   else
  return 1;
}

OUTPUT:
     Enter any number
      4
     factorial of given number 4 is 1


                      C program to find the GCD of two numbers


C program to find Factorial of a given number using recursive and non recursive functions
            

No comments:

Post a Comment