C语言for语句求...s=1!-2!+3!-4!+…+9!-10!的值

不要用递归函数fan,就只用for语句....
我的思路是13579为一组,246810为另一组,两组相加即可
图片分享

望采纳!

#include <stdio.h>

#include <stdlib.h>

int main(void)

{

    int cnt = 0;

    int Factorial = -1;

    int Sum = 1;

    for(cnt = 1; cnt <= 10; cnt++)

    {

        Factorial = Factorial * cnt * (-1);

        printf("%d\n",Factorial);

        Sum = Sum + Factorial;

    }

    printf("the sum is %d\n", Sum);

    return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-25
把你的算阶乘的函数中累乘时候使用i=-1开始,每次i--;这样奇数向是负的,偶数项是正的
然后累加,最后乘-1

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网