Suppose we have a number N, our task is to find ln(N!) using recursion. ln() is basically log base e. To solve this we can use this formula −
$$\ln\lgroup N!\rgroup=\ln\lgroup N*\lgroup N-1\rgroup *\lgroup N-2\rgroup *\dotsm*2*1\rgroup=\ln\lgroup N\rgroup+\ln\lgroup N+1\rgroup+\dotsm+\ln\lgroup 1\rgroup$$
Example
#include<iostream>
#include<cmath>
using namespace std;
double factLog(int n) {
if (n <= 1)
return 0;
return factLog(n - 1) + log(n);
}
int main() {
int N = 3;
cout << factLog(N);
}Output
1.79176