如何估算此问题的答案:
e = 1+ 1/1! + 1/2! + 1/3!+...
我知道我的解决方案不正确,但是什么是正确的解决方案?为什么在编译时却没有给出错误提示,但是却表示该应用已停止工作
#include <iostream>
using namespace std;
int main()
{
int x;
cout <<"Enter the accuracy of the expression "
<<"1+1/1!+1/2!+1/3!+... :";
cin >> x;
int factorial;
int counter = 1;
int x2;
int e = 0;
x2 = x;
factorial = x;
while(x2 > 1)
{
while(counter <=x2 && x>0)
{
factorial*=(x-1);
x = x-1;
counter++;
}
factorial = 1/factorial;
e+=factorial;
x2--;
x = x2;
factorial = x2;
}
e+=1;
cout <<"The answer is "<<e;
}