c语言s=1-3+5-7+....-99+101

#include <stdio.h>
//s=1-3+5-7+....-99+101
main()
{
    int i,t=1,s=0;
    for(i=1;i<=101;i+=2)
    {
        t=t*i;
        s=s+t;
        t=-t/i;
    }
    printf("%d\n",s);
 getchar();
 }

 

#include <stdio.h>
//s=1-3+5-7+....-99+101
main()
{
    int i,t=1,s=0;
    for(i=1;i<=101;i+=2)
    {
        t=t*i;
        s=s+t;
        t=-i/t;
    }
    printf("%d\n",s);
 getchar();
 }

 

posted @ 2021-11-10 09:25  myrj  阅读(1897)  评论(0编辑  收藏  举报