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.


E
Sections
12
Exercises

A

B

C

D

E

1

2

3

4

5

6

7

8

10

11

12

13

14

15

16

9

#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;
}

© 2020 Garbage Valuegarbage value logo