#include<stdio.h>
int main()
{
int i = 0, sum = 0, n = 1,tmp=1;
for (n = 1; n < 11; n++)
{
tmp = 1;
for (i = 1; i <= n; i++)
{
tmp *= i;
}
sum += tmp;
}
printf("%d\n", sum);
system("pause");
return 0;
}
这个代码很罗嗦 非常不好
可以优化为
#include<stdio.h>
int main()
{
int i = 0, sum = 0, n = 1,tmp=1;
for (n = 1; n < 4; n++)
{
tmp *= n;
sum += tmp;
}
printf("%d\n", sum);
system("pause");
return 0;
}
时间: 2025-01-04 07:56:22