L1-013计算阶乘和

题目描述:

对于给定的正整数N,需要你计算 S = 1! + 2! + 3! + ... + N!。

输入格式:
输入在一行中给出一个不超过10的正整数N。

输出格式:
在一行中输出S的值。

输入样例:
3

输出样例:

9

#include<iostream>
using namespace std;

int main(){
	int N;
	cin>>N;
	
	int result = 0;
	for(int i=1;i<=N;i++)
	{
		int num = 1;
		for(int j=i;j>1;j--)
		{
			num *= j;
		}
		result += num;
	}	
	cout<<result;
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/numbstorm/article/details/80026824