Factorial of a number using Recursion in C++

C++ Program to find the Factorial of a number using Recursion

Source code :


#include <iostream>

using namespace std;

int factorial(int);

int main(){
    
    int number = 3; // Change your number here
    
    cout<<"The factorial value of "<< number <<" is "<< 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 :