Saturday, January 30, 2010

CHAP 3[E](m) Approximating natural log

The natural logarithm can be approximated by the following series.






If x is input through the keyboard, write a program to calculate the sum of first seven terms of this series.


void main()
{
float v,w,x,y,z;
v=0;
w=1;
printf("\nInput the value of x for which the it takes on the natural log");
scanf("%f",&x);
y=(x-1)/x;

for(z=1;z<=7;z++)
{
w*=y;
v+=0.5*w;
}

printf("\nThe sum of the first seven terms is %f",v+0.5*y);
}

3 comments: