Files
class-notes/2207/天天乐学答案/C语言/3-4/10/Prog1.c
T
2025-03-04 20:10:05 +08:00

24 lines
470 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*-------------------------------------------------------
编程计算:s=1!+3!+5!+…n! (n由键盘输入,使用for循环)
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,n;
long p,sum;
sum=0;
printf("请输入一个正整数n:");
scanf("%d",&n);
/**********Program**********/
p = 1;
for ( i = 1;i <= n; i++ ) {
p *= i;
if ( i%2 == 1 ) {
sum += p;
}
}
/********** End **********/
printf("1!+3!+...+%d!= %d\n",n,sum);
}