C language programming> 20th week① Please add the main function, the function of this function is to find the sum of 1+2!+3!+…+N!.

Example: Please add the main function. The function of this function is to find the sum of 1+2!+3!+…+N!.

例如,1+2!+3!+…+9!的和为409113。
注意:仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其他任何内容。

代码如下:

#include<stdio.h>
main()
{
    
    
	int i,n;
	long sum=0,temp=1;
	printf("\nInput n:\n");
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
    
    
		temp=temp*i;
		sum=sum+temp;
	}
	printf("1!+...+%d!=%ld\n",n,sum);
}

The output running window is as follows:
Insert picture description here

越努力越幸运!
加油,奥力给!!!

Guess you like

Origin blog.csdn.net/qq_45385706/article/details/112760092