#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
// calculation of ln x
double Lnx(double n)
{
double num, mult, cal, sum = 0;
num = (n - 1) / (n + 1);
//ending the loop
// improving the precision
for (int i = 1; i <= 1000; i++) {
mult = (2 * i) - 1;
cal = pow(num, mul);
cal = cal / mul;
sum = sum + cal;
}
sum = 2 * sum;
return sum;
}
// Driver Code
int main()
{
double lnx, param, t = 6;
param = cosh (t);
lnx = Lnx(param);
// setprecision(3) is used to display
// the output up to 3 decimal places
cout << fixed << setprecision(3)
<< "ln (cosh) " << t << " = "
<< lnx << endl;
}
Comments
Leave a comment