21天养成计划-16
求1!+2!+3!+……+n!
#include <stdio.h>
int main(void)
{
int i, j, n;
int p = 1, sum = 0;
printf(“input n = “);
scanf(”%d”, &n);
for (i=1; i<=n; i++)
{
p = 1;
for (j=1; j<=i; j++)
{
p *= j;
}
sum += p;
}
printf(“1!+2!+3!+…+n! = %d\n”, sum);
return 0;
}
2021-11-13
最新推荐文章于 2022-01-29 16:30:08 发布