estimates the value of constant e

2008-10-23 1:30 pm
Write a C program that estimates the value of the mathematical constant e by using the formula:

e = 1 + 1/1! + 1/2! + 1/3! + …

謝謝

回答 (1)

2008-10-23 7:34 pm
✔ 最佳答案
double sum=1, fact=1;
int nTerms=20;
for(int i=1;i<=nTerms;i++)
{
fact=fact*i;
sum=sum+1/fact;
}
printf("the value of e evaluated to %d terms is %f\n",nTerms, sum);


收錄日期: 2021-04-13 16:11:04
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20081023000051KK00232

檢視 Wayback Machine 備份