Factorial of a number using Recursion in C

Factorial of a number using Recursion

Source code :


#include <stdio.h>

int factorial(int);

int main(){
    
    int number = 3; // Change your number here
    
    printf("The factorial value of %d is %d",number,factorial(number));
    
    return 0;
    
}

int factorial(int n) {
  if (n == 0) {
    return 1;
  }
  
  return n * factorial(n - 1);  // Here's the recursion
}


Output :

The factorial value of 3 is 6

Output :


                

Comments :