Home C Programming Language / 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,539 Views
💻 Practical Program
📘 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;
}

                        

🖥 Program Output


 Approximate value of e is: 2.718282
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.