This question requires the preparation of program that calculates the sequence 1!+2!+3!+⋯
of front N
and Paragraph.
Input format:
Enter a positive integer not exceeding 12 in one line N
.
Output format:
Output integer results in one line.
Input sample:
5
Sample output:
153
Code:
# include <stdio.h>
# include <stdlib.h>
int main() {
int N,sum = 0,i,j,value;
scanf("%d",&N);
for (i=1;i<=N;i++) {
value = 1;
for (j=1;j<=i;j++) {
value *= j;
}
sum += value;
}
printf("%d",sum);
return 0;
}
Submit screenshot:
Problem-solving ideas:
Pay attention to the factorial operation, it N!
means 1*2*……N
, so N
you must use a two-layer loop to traverse when finding the sum of the antecedents!