write a c program the computes the value e^x

2008-10-24 4:31 pm
write a c program the computes the value ex by using the
formula
e^x=1+x/1!+xsquare/2!+xcube/3!+....



//chap 4.35(c)

#include <iostream>

using namespace std;

int main()
{
while (true) {
int x;
long n=30;
double factorial = 1;
double e=1.0;

cout<<"請輸入一個整數x\n";
cin>>x;
if (x>=0){
for(int i=1;i<=n;i++)
{
factorial = i * factorial;
e += x/factorial;
x=x*x;
}

}
cout<<"e^x的值為:"<<e<<endl;
}
return 0;}


可以編譯,但出來的數值不太對

回答 (1)

2008-10-29 4:08 pm
✔ 最佳答案
...Please check following code: import java.io.*; public class CalAmount { public static void main(String[ ] args) { PrincipalRateAmount PRA = new PrincipalRateAmount( ); PRA.SetPrincipalRatePeriod
參考: me


收錄日期: 2021-04-23 12:43:38
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20081024000051KK00261

檢視 Wayback Machine 備份