C program to find FACTORIAL OF GIVEN NUMBER USING RECURSIVE FUNCTION

C program to find factorial of given number using recursive function

  1. #include <stdio.h>
  2. int factorial(int);
  3. int main() {
  4.    int number;
  5.    printf("Enter your number:");
  6.       scanf("%d", &number);
  7.    printf("Factorial of %d is %d\n", number, factorial(number));
  8.       return 0;
  9.       }
  10.       int factorial(int i)
  11.       {
  12.          if(i<=1) {
  13.                return 1;
  14.                   }
  15.                      return (i*factorial(i-1));
  16.                      } 

Output

Enter your number:5
Factorial of 5 is 120
choose next program from this list

Comments