注册 登录
编程论坛 C++教室

级数 问题~~ 来看看对错~

beyondjoe 发布于 2007-11-20 13:06, 477 次点击
1+x-x^2/2!+x^3/3!…(-1)^(n+1)x^n/n!
这个代码对不对? 运行的有点奇怪啊~
#include<iostream.h>
#include<cmath>
#include<stdlib.h>
int main(){
int x,ITEM;
double SUM=1,CF=1,JC=1;
cin>>x;
for(int n=1;abs(ITEM)>1e-6;++n){
CF*=-x;
JC*=n;
ITEM=(-1)*CF/JC;
SUM+=ITEM;
}
cout<<SUM<<endl;
system("pause");
}

[此贴子已经被作者于2007-11-20 17:31:46编辑过]

2 回复
#2
beyondjoe2007-11-20 13:08
输出精度为10^(-8)
#3
nuciewth2007-11-20 15:55
int x,ITEM,SUM=0,CF=1,JC=1;
1