I was asked to calculate the following nested root expression using recursion only.
I wrote the code below that works, but they allowed us to use only one function and 1 input n for the purpose and not 2 like I used.
Can someone help me transform this code into one function that will calculate the expression? cant use any library except functions from <math.h>.
output for n=10: 1.757932
double rec_sqrt_series(int n, int m) {
if (n <= 0)
return 0;
if (m > n)
return 0;
return sqrt(m + rec_sqrt_series(n, m + 1));
}
double helper(int n) {
return rec_sqrt_series(n, 1);
}
