使用函数实现求下列值 1!+1!+2!+1!+2!+3!+……+1!+2!+3!+……+n!用C语言嵌套jck
时间: 2023-12-07 21:39:03 浏览: 103
登陆加密MD5+Salt+SHA1附代码
以下是使用函数实现求下列值的C语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
int Factor(int n) //计算n的阶乘
{
int result = 1;
for (int i = 1; i <= n; i += 1) {
result *= i;
}
return result;
}
int FactorSum(int n) //计算1!+2!+3!+...+n!的和
{
int sum = 0;
for (int i = 1; i <= n; i += 1) {
for (int j = 1; j <= i; j += 1) {
sum += Factor(j);
}
}
return sum;
}
int main()
{
int n = 5; //n为5
int result = FactorSum(n);
printf("result = %d\n", result);
system("pause");
return 0;
}
```
阅读全文