求1到n的阶乘之和

 阶乘之和

#include 
using namespace std;
int main()
{
	int n;
	cout << "请输入数字:" << endl;
	cin >> n;
	if (n < 0 || n == 0)
	{
		cout << "请重新输入有效数字" << endl;
	}
	else
	{
		long long sum = 0, factorial = 1;    //sum为阶乘之和,factorial为i的阶乘    
		for (int i = 1; i <= n; i++)
		{
			factorial *= i;
			//cout << factorial<<"\t";输出各个数字的阶乘
			sum += factorial;
		}
		cout << "阶乘之和是"<

 

你可能感兴趣的:(c++,大数据)