【C语言】阶乘求和

阶乘求和

题目描述
求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一个数字(n不超过20)。

输入
n

输出
Sn的值

#include<stdio.h>
int main()
{
	int n;
	long sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		long temp=1;
		for(int j=1;j<=i;j++)
		{
			temp*=j;
		}
		sum+=temp;
	}
	printf("%ld",sum);
}
发布了31 篇原创文章 · 获赞 21 · 访问量 1630

猜你喜欢

转载自blog.csdn.net/weixin_46014378/article/details/104471388
今日推荐