阶乘之和

时间:2021-08-29 19:08:37   收藏:0   阅读:25
#include<stdio.h>
#include<math.h>
int step(int a)
{
    int power=0;
    if (a == 1 || a == 0)
        power = a;
    if (a > 1)
        power= a*step(a-1);
    return power;
}

int main()
{

    int m,n;
    long sum = 0;
    printf("请输入n:\n");
    scanf_s("%d",&n);
    for (m=1;m<=n; m++ )
    {
        sum = sum + step(m);
    }
    printf("1!+2!+3!+...+n!=%d", sum);
}

 

原文:https://www.cnblogs.com/zrzsblog/p/15202002.html

评论(0)
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!