我的第18个代码

2021-02-20 16:57发布

我的第十八个代码

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