I have been given a question to write a program to read a number x from the user and then
print the value of ln(1+x).

I have been given the following equation to perform the calculation:

``````1     2     3     4     5     6       100
ln(1+x) =  x     x     x     x     x     x       x
--- - --- + --- - --- + --- - --- ... ---
1     2     3     4     5     6      100``````

but I did not know how to calculate the lawn x value. Can someone here kind enough to guide me through this????

What exactly is the purpose of this program, what's it suppose to do?

Ok, so what you'll start with is some value x, and you'll write a function that computes ln(1+x) by using the formula above:

``````double ln_one_plus_x(double x)
{
double val;
// insert math here
return val;
}``````

Now you want to use exponents from 1 to 100 inclusive, so a loop is in order.
Each term will be added (if the exponent is odd) or subtracted (if the exponent is even) to/from the total. And instead of computing the powers-of-x for each term, you can notice that x^57 = (x^56 * x). And then the power-of-x for each term must also be divided by the power. Is that enough to get you started? If you need to test your result, try http://www.cplusplus.com/reference/clibrary/cmath/log/ (and note that the formula given is valid when |x| < 1, otherwise the powers-of-x grow instead of shrink and the formula diverges from any solution).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.