Friday, September 30, 2016

Factorial of given number using recursive function.

Recursive Function

The function which calls itself is called recursive function.


Factorial of given number using recursive function.



#include <stdio.h>
int factorial(int);

int  main() {
   int number;
  
   printf("Enter your number:");
   scanf("%d", &number);
  
   printf("Factorial of %d is %d\n", number, factorial(number));
   return 0;
}
int factorial(int i)
{
   if(i<=1) {
      return 1;
   }
   return (i*factorial(i-1));
}


Output of the program

Enter your number:5
Factorial of 5 is 120


No comments:

Post a Comment