作业帮 > 综合 > 作业

根据公式e=1+1/1!+1/2!+1/3!+...求e的近似值,精度要求为0.00001.大神之需看一下我做的为什么不

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 11:50:46
根据公式e=1+1/1!+1/2!+1/3!+...求e的近似值,精度要求为0.00001.大神之需看一下我做的为什么不对.
/*#include #include using namespace std; int main(void) { int n=1; float s=0.0; int i=1; while(fabs(1.0/float(n))>0.00001) { s = s+1.0/float(n); n = n*i; i = i+1; } cout
#include #include using namespace std; int main() { int n=1; float s=0.0; int i=1; while(fabs(1.0/float(n))>0.00001) ; //这里有问题,将 ;去掉 { s=s+1.0/float(n); n=n*i; i=i+1; } cout