【1031】求阶乘和

描述:

给你一个正整数n,请你求1n的阶乘的和,并输出最后结果
如给你5 , 即计算 1!+2!+3!+4!+5!
Input a positive integer n,and calculate the sum of n!.For example,n is 5 andcalculate the following formula:
1!+2!+3!+4!+5!

输入:

一个正整数n
a positive integer n.

输出:

求得的阶乘和
The sum of n!

输入样例:

5

输出样例:

153


#include<iostream>
using namespace std;
int main()
{
	int n,i,a=1,s=0,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=i;j++)
		{
			a=a*j;
		}
		s=a+s;
		a=1;
	}
	cout<<s<<endl;
	return(0);
}


猜你喜欢

转载自blog.csdn.net/qq_40560275/article/details/78322324
今日推荐