Page Rank Checker

Saturday 5 July 2014

Sum Of First 7 Terms Of Natural Logarithm Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. The natural logarithm can be approximated by the following series.
 
Ans.

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
    clrscr();
    float x, ans=0, f_ans=0, s_ans;
    int n;
    printf("enter the value of x ");
    scanf("%f",&x);
    for(n=1;n<=7;n++)
    {
        if(n==1)
        {
            ans=pow(((x-1)/x),n);
        }
        else
        {
            s_ans=pow(((x-1)/x),n);
            ans=s_ans/2;
        }
        f_ans=f_ans+ans;
    }
    printf("Sum of first seven terms is %f",f_ans);
    getch();
}