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

The natural logarithm can be approximated by the following series.

Program:115

The natural logarithm can be approximated by the following series.


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

#include<stdio.h>
#include<conio.h>
#include<math.h> //because we have to use pow function
int main()
{
    int i;
    float x,d,p,r,res=0;
    printf("Enter the value of x: ");
    scanf("%f", &x);
    d=(x-1)/x;
    //for-loop for seven terms
    //loop will start from second term
    //because first is already assigned via d=(x-1)/x
    for(i=2;i<=7;i++)
    {
        p = pow(d,i);
        r = p/2;
        res = res + r;
    }
    //for first term we have d=(x-1)/x
    res = d + res;
    printf("Result: %f",res);
}

Output:

Enter the value of x: 5
Result: 1.980570

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.