factorial using recursion c++ code example
Example 1: factorial in c++
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int fact(int i){
if (i <= 1) return 1;
else return i*fact(i-1);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
cout << fact(N) << "\n";
return 0;
}
Example 2: c++ factorial
#include <cmath>
int fact(int n){
return std::tgamma(n + 1);
}
Example 3: fcatorianls c++
#include <iostream>
int factorial (int n)
{
if (n ==0)
{
return 1;
}
else
{
return n * factorial(n-1);
}
}