1!+2!+……+20!用c语言编程,使用for语句
时间: 2023-11-24 10:51:29 浏览: 96
C语言中的for语句
以下是使用for语句在C语言中计算1!+2!+……+20!的代码:
```c
#include <stdio.h>
int main() {
int i, j;
long long factorial, sum = 0;
for (i = 1; i <= 20; i++) {
factorial = 1;
for (j = 1; j <= i; j++) {
factorial *= j;
}
sum += factorial;
}
printf("1!+2!+...+20! = %lld", sum);
return 0;
}
```
阅读全文