Write a program to compute the mathematical constant e, the base of natural loga
ID: 2945618 • Letter: W
Question
Write a program to compute the mathematical constant e, the base of natural logarithms, from the definition e = lim n rightarrow infinity (1 + 1/n)n. Specifically, compute (1 + l / n )n for n = 10k, k = 1,2,...,20. If the programming language you use does not have an operator for exponentiation, you may use the equivalent formula (1 + l/n)n = exp(n log(l + 1/n)), where exp and log are built-in functions. Determine the error in your successive approximations by comparing them with the value of exp(l). Does the error always decrease as n increases? Explain your results.Explanation / Answer
#include <stdlib.h> double compute_ex(float); int main() {float x; printf(" enter the value of x "); scanf("%f",&x); printf("%.2f",compute_ex(x)); return 0; } double compute_ex(float x) { int i=1,m,k,n=1; float result,p=1.0,term=1.0; result+=term; while(term>=0.0001) { for(m=1;m<=i;m++) { p*=x; } for(k=1;k<=i;k++) { n*=k; } term=p/n; result+=term; i++; p=1.0; n=1; } return result; } #include <stdio.h>Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.