Home / Programs / 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.
Programming Example

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.

👁 7,538 Views
💻 Practical Program
📘 Step by Step Learning
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 p

Program Code

#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

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.