#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int compute(int num) {
int sum = 1;
for (int i = 1; i < num+1;i++) {
sum = i * sum;
}
return sum;
}
int main() {
//2,计算1!+2!+...+10!
int sum2 = 0;
for (int i = 1; i < 11;i++) {
sum2 = compute(i) + sum2;
}
printf("1!+2!+...+10的和为:%d ", sum2);
return 0;
}
注意int型的内存溢出情况!传进去的参数num不能过大!