Friday, 2 August 2013

Chapter 3 Solutions Problem [E][m]

Question-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.

Solution- Easy one . check it out .

#include <stdio.h>
#include<math.h>

int main()
{

    float x,ans=0,i;
    printf("Enter the value of x\n");
    scanf("%f",&x);
    for(i=1;i<=7;i++)
    {
        ans=ans+(1/i)*pow((x-1)/x,i);
    }
    printf("Answer=%f\n",ans);
    return 0;

}

2 comments:

  1. I am not sure, but this might work..
    #include
    #include
    int main ()
    {
    float x, i, j=0, ans;
    printf("Enter The Value Of X: ");
    scanf("%f",&x);
    ans= (x-1)/x;

    for (i=1; i<=7; i++)
    {
    ans=ans + (1/ 2) *pow ((x-1)/x , i);
    }
    printf("Answer = %.2f", ans);
    return (0);
    }

    ReplyDelete