求C语言编程 1.计算:sum=1-1⼀2!+1⼀3!-1⼀4!+ …… -1⼀10! 2.编写一个函数,由实参传来一个字符串,统计此

2024-12-05 03:16:48
推荐回答(1个)
回答1:

1.
include
int main(void){
int sign = 1;
long int f = 1,s = 0;
for(int i = 1;i < 11;++i){
f *= i;
if(i % 2){sign = -1}
s += (1 / f * sign);
}

printf("结果为%i\n",s);

return 0;
}