使用c++,输入整数n, 编程计算 sum=1!+2!+...+n!。
时间: 2023-11-17 22:00:23 浏览: 72
1!+2!+..n!
```c++
#include <iostream>
using namespace std;
int main() {
int n;
double p = 1, sum = 0;
cout << "请输入一个整数:";
cin >> n;
for (int i = 1; i <= n; i++) {
p *= i;
sum += p;
}
cout << "1!+2!+...+" << n << "! = " << sum << endl;
return 0;
}
```
阅读全文