C语言编程求sum=1!+2!+3!+4!+5!
时间: 2023-07-08 13:17:03 浏览: 235
给出一个百分制成绩,要求输出其对应的成绩等级以及编程实现1!+2!+3!+4!+5!
好的,以下是C语言代码实现:
```c
#include <stdio.h>
int main() {
int n = 5;
int sum = 0;
int factorial = 1;
for (int i = 1; i <= n; i++) {
factorial *= i;
sum += factorial;
}
printf("sum = %d\n", sum);
return 0;
}
```
运行结果为:sum = 153
阅读全文