我的第18个代码

我的第十八个代码

#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!的结果(对上面代码的优化)

猜你喜欢

转载自blog.51cto.com/15100722/2633206

相关文章