Write a program to solve the following problem- Euler's number e is used as the base of natural logarithms. It may be approximated using the following formula: where n is sufficiently large. Write a program that approximates e using a loop that terminates when the difference between the two successive values of e is less than 0.0000001.

C Programming Language / Loop control in C Language

7519

Program:

#include <stdio.h>
int main()
{
	double term = 1.0;
	double sum = 1.0;
	int n = 0;
	while (term >= 0.0000001)
	{
		n++;
		term = term/n;
		sum = sum + term;
	}
	printf("\n Approximate value of e is: %lf ",sum);
	
	getch();
	return 0;
}

Output:

 Approximate value of e is: 2.718282

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.