求m!+n!的值c++
时间: 2024-06-13 18:10:01 浏览: 4
以下是求m!+n!的C++代码实现:
```c++
#include <iostream>
using namespace std;
int main() {
int m, n, sum = 0;
int i, j, m_factorial = 1, n_factorial = 1;
cout << "请输入m和n的值:" << endl;
cin >> m >> n;
// 计算m的阶乘
for (i = 1; i <= m; ++i) {
m_factorial *= i;
}
// 计算n的阶乘
for (j = 1; j <= n; ++j) {
n_factorial *= j;
}
// 计算m!+n!的值
sum = m_factorial + n_factorial;
cout << "m!+n!=" << sum << endl;
return 0;
}
```
相关问题
C++计算m!+n!
以下是C++计算m!+n!的代码示例:
```cpp
#include <iostream>
using namespace std;
int main() {
int m, n;
unsigned long long m_factorial = 1, n_factorial = 1, sum = 0;
cout << "请输入m和n的值:" << endl;
cin >> m >> n;
// 计算m的阶乘
for (int i = 1; i <= m; i++) {
m_factorial *= i;
}
// 计算n的阶乘
for (int i = 1; i <= n; i++) {
n_factorial *= i;
}
// 计算m!+n!
sum = m_factorial + n_factorial;
cout << "m!+n!=" << sum << endl;
return 0;
}
```
c++计算m!+n!
以下是C++计算m!+n!的代码示例:
```cpp
#include <iostream>
using namespace std;
int main() {
int m, n;
unsigned long long m_factorial = 1, n_factorial = 1, sum = 0;
cout << "请输入m和n的值:" << endl;
cin >> m >> n;
// 计算m的阶乘
for (int i = 1; i <= m; i++) {
m_factorial *= i;
}
// 计算n的阶乘
for (int i = 1; i <= n; i++) {
n_factorial *= i;
}
// 计算m!+n!
sum = m_factorial + n_factorial;
cout << "m!+n!=" << sum << endl;
return 0;
}
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)