计算2+22+222

#include
using namespace std;
int main()
{
	int n;
	int sum = 1;
	int total = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		sum = sum*i;
		total += sum;
	}
	cout << total << endl;
	system("pause");
}
 
  

计算阶乘相加1!+2!+3!

#include
using namespace std;
int main()
{
	int n;
	int sum = 1;
	int total = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		sum = sum*i;
		total += sum;
	}
	cout << total << endl;
	system("pause");
}


你可能感兴趣的:(c/c++,每天练点小程序)