急救中~~~~~~~~~~~

来源:百度知道 编辑:UC知道 时间:2024/07/08 17:36:59
y=1+1/1!+1/2!+1/3!+...+1/100!
用C++编写程序
小弟在此跪谢了。。所有分都给你了

给,已经编译运行确认:

#include<iostream.h>
int f(int n);
int main()
{
double e, t = 1;
int n = 1;
while (n<=100)
{
e = t + 1.0/f(n++);
if ( e-t < 0.0000001) break;
t = e;
}
cout<<e<<endl;
return 0;
}

int f(int n)
{
int result = 1;
for(int i=1;i<=n; i++ )
{
result *= i;
}
return result;
}

运行结果为:2.71828

#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
double value =1.0;
double total = 1.0;
for(int i=2; i<101; ++i)
{
value /= i;
total += value;
}
cout<<"total="<<total<<endl;
return 0;
}

#include "iostream"
using namespace std;

void main()
{
double jiecheng = 1;
double y = 0;
for (int