The following series summation is an approximation for computing the natural logarithm of a floatingpoint
value x:
logx=[(x-1)]–[[(x-1)^2]/2]+[[(x-1)^3]/3]–[[(x-1)^4]/4]+….+(-1)n+1(x-1)^n/n
Where 2 >= x > 0 and n is a positive integer.
Design and implement an interactive program that does the following:
1. Prompts the user to enter a floating-point value for x and reads it.
2. Ensures that x is in the proper range; if not, re prompts the user to enter another value.
i've done it like this...
float x = 123.45F; // example value to find the log
float x1 = (x - 1);
for(int i = 1; i < n; i++)
{
float k = ( pow((x-1), i) / i );
if( (i % 2) == 0)
x1 -= k;
else
x1 += k;
}
i dont know how to edit the i.
because if it like that it will become (x-1)-((x-1)^1)/1 where the result will zero.
value x:
logx=[(x-1)]–[[(x-1)^2]/2]+[[(x-1)^3]/3]–[[(x-1)^4]/4]+….+(-1)n+1(x-1)^n/n
Where 2 >= x > 0 and n is a positive integer.
Design and implement an interactive program that does the following:
1. Prompts the user to enter a floating-point value for x and reads it.
2. Ensures that x is in the proper range; if not, re prompts the user to enter another value.
i've done it like this...
float x = 123.45F; // example value to find the log
float x1 = (x - 1);
for(int i = 1; i < n; i++)
{
float k = ( pow((x-1), i) / i );
if( (i % 2) == 0)
x1 -= k;
else
x1 += k;
}
i dont know how to edit the i.
because if it like that it will become (x-1)-((x-1)^1)/1 where the result will zero.
Comment