用c++求1!+2!+3!+...+8!
时间: 2023-11-17 20:00:21 浏览: 172
c++ 1!+2!+3!+..
下面是用C++求1!+2!+3!+...+8!的代码:
```c++
#include <iostream>
using namespace std;
int main() {
int n = 8;
unsigned long long sum = 0;
unsigned long long fac = 1;
for (int i = 1; i <= n; i++) {
fac *= i;
sum += fac;
}
cout << "1!+2!+3!+...+8!=" << sum << endl;
return 0;
}
```
输出结果为:1!+2!+3!+...+8!=40,320,240
阅读全文