Hello, it is quite easy for me to divide 1/(2/(3/4)) by recursion (if k = 3 then output will be 0.375), but the trouble is that i dont know how to add numbers to this like 1/(1 + [2/(2 + [3/4])])
#include <iostream>
usingnamespace std;
//============================
double continuedFraction( int k, int n )
{
if ( n == k ) return 1.0;
elsereturn n / ( n + continuedFraction( k, n + 1 ) );
}
//============================
int main()
{
int k;
cout << "Input last term, k: ";
cin >> k;
cout << "Continued fraction partial sum = " << continuedFraction( k, 1 );
}