Calculate 1!+2!+3!+...+n! and output the result

Calculate 1!+2!+3!+…+n! and output the result The
code is as follows:

#include <stdio.h>
int main(){
    
    
	
	int n=0,i=0,j=0;
	long result=0;
	printf("输入 n:\n");
	scanf("%d",&n);
	for(i=1;i<=n;i++){
    
    
		int tem=1;
		for(j=i;j>0;j--){
    
    
			tem = tem*j;
		}
		result = result+tem; // 计算累计的和
	}
	printf("结果为:%d\n",result);

	return 0;
}

Guess you like

Origin blog.csdn.net/G_whang/article/details/113099737