阶乘之和

#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);
}

 

阶乘之和

上一篇:22-26


下一篇:标识符和关键字