0条评论
还没有人评论过~
我的第十八个代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
int a = 1;
int ret = 1;
int n = 1;
int sum = 0;
for (n = 1; n <= 10; n++)
{
ret = 1;
for (a = 1; a <= n; a++)
{
ret = a*ret;
}
sum = ret + sum;
}
printf("%d\n", sum);
return 0;
}//计算1!+2!+3!……10!的结果
int main()
{
int a = 1;
int ret = 1;
int n = 1;
int sum = 0;
for (n = 1; n <= 10; n++)
{
ret = ret*n;
sum = ret + sum;
}
printf("%d\n", sum);
return 0;
}//计算1!+2!+3!……10!的结果(对上面代码的优化)
来源:51CTO
作者:大圣?
链接:https://blog.51cto.com/15100722/2633206