当前位置:网站首页>2.6 finding the sum of the first n terms of factorial sequence

2.6 finding the sum of the first n terms of factorial sequence

2022-06-25 19:57:00 Then peace and happiness

Programming , Calculation sequence 1!+2!+3!+⋯ Before N Sum of items .‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬

Input format :

The input gives no more than 12 The positive integer N.‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬

Output format :

Output integer results on one line .‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬

sample input :

5

sample output :

153

Reference code :

#include<stdio.h>
#include<math.h>
double fact(int n);
int main(void)
{
	int i,N;
	double sum=0;
	scanf("%d",&N);
	for(i = 1;i <= N;i++){
	sum =sum + fact(i);
}
	printf("%.0f",sum);
return 0;
}

double fact(int n)
{
	int i;
	double product = 1;
	for(i = 1; i <= n; i++){
		product = product * i;
	}
	return product;
}

原网站

版权声明
本文为[Then peace and happiness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190512045730.html