Ad

Chapter - 4: The Loop Control Structure

he natural logarithm can be approximated by the following series. (x - 1)/x + 1/2((x - 1)/2)^2 + 1/2((x-1)/2)^3 + ... If x is input through the keyboard, write a program to calculate the sum of first seven terms of this series.


Ad
E
Sections
12
Exercises
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
	int i,a;
	float sum,act,term,x;
	
	printf("Enter the value of x : ");
	scanf("%f", &x);
	
	a=2;
	term=(x-1)/x;
	sum=term;
	
	for(i=1;i<=6;i++)
	{
		act=pow(term,a)/2;//series according to the book.
		//act=pow(term,a)/a; //actual natural log series.
		sum=sum+act;
		a++;
	}
	
	printf("%f is the sum of the series.\n", sum);
	
	getch();
	return 0;
}
Ad

© 2024 Garbage Valuegarbage value logo