第五章3

1+2!+3!+...+n!的和。

输入

 

正整数n(n〈=10)

输出

 

1+2!+3!+...+n!的和 (结果为整数形式)

【样例输入】

3

【样例输出】

9

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,i,j,tot=1,sum=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
            //tot*=i;
        for(j=1;j<=i;j++){
            tot*=j;
        }
    sum+=tot;
    tot=1;
    }
    printf("%d",sum);
    return 0;
}

 

posted @ 2022-10-26 16:57  aquAAA  阅读(48)  评论(0编辑  收藏  举报