#include <stdio.h>
double my_log(double x)
{
double epsilon = 1e-15;
double y = (x - 1) / (x + 1);
double y_squared = y * y;
double term = y;
double sum = term;
int k = 1;
while (term > epsilon)
{
term *= y_squared;
sum += term / (2 * k + 1);
k++;
}
return 2 * sum;
}
int main()
{
double x = 0.0;
printf("input x \n");
scanf("%lf", &x);
double log_x = my_log(x);
printf("ln(%f) = %f \n", x, log_x);
return 0;
}
用泰勒公式