Hi Deji! Here is my proposal for this, which seems to work well for me :-)
double ln_approx(double x, int n) {
double accumulator = 0;
// The Taylor series is in terms of "x+1".
x = x - 1;
for (int i = 1; i <= n; i++) {
const int multiplier = i % 2 == 0 ? -1 : 1;
accumulator += multiplier * pow(x, i) / i;
}
return accumulator;
}
int main(int argc, char** argv) {
const double x = atof(argv[1]);
const int n = atoi(argv[2]);
const double result = ln_approx(x, n);
printf("ln(%f) ~= %f (%i iterations)\n", x, result, n);
}