c++程序1!+3!+5!+..+n!的和的代码
时间: 2024-01-02 13:21:33 浏览: 118
C++代码和程序
以下是C++程序实现1!+3!+5!+...+n!的和的代码:
```c++
#include <iostream>
using namespace std;
int main() {
int n, sum = 0, fac = 1;
cout << "请输入n的值:";
cin >> n;
for (int i = 1; i <= n; i += 2) {
fac = 1;
for (int j = 1; j <= i; j++) {
fac *= j;
}
sum += fac;
}
cout << "1!+3!+5!+...+n!的和为:" << sum << endl;
return 0;
}
```
阅读全文