#include<stdio.h>
//64位机器最多只能取到n = 31,再大数据会溢出
int main(){
int n = 0;
long long int result = 0, tmp = 1;
printf("Please input n to calculate 1! + 2! + ...+ n!:\n");
scanf_s("%d", &n);
if (n < 1){
printf("Input wrong.\n");
return 0;
}
for (int i = 1; i <= n; ++i){
tmp *= i;
result += tmp;
}
printf("The result is %lld\n", result);
return 0;
}
温馨提示:答案为网友推荐,仅供参考