6.4 求 ,(即求1!+2!+3!+4!+5!+...+n!)用C语言
时间: 2023-09-17 15:09:36 浏览: 51
C语言编写1!+2!+3!+.....+n!.doc
#include <stdio.h>
int main() {
int n, i, j, factorial;
printf("请输入n的值:");
scanf("%d", &n);
printf("1! 2! 3! ... %d! 的值分别为:\n", n);
for (i = 1; i <= n; i++) {
factorial = 1;
for (j = 1; j <= i; j++) {
factorial *= j;
}
printf("%d! = %d\n", i, factorial);
}
return 0;
}
阅读全文