习题二 5

#include<stdio.h>
int main(void)
{
    int i,n,numerator,denominator,flag;
    double sum,item;

    printf("Enter n:");
    scanf("%d",&n);
    numerator=1;
    denominator=1;
    sum=0;
    flag=1;
    
    for(i=1;i<=n;i++){
        item=flag*(numerator*1.0/denominator);
        numerator=numerator+1;
        denominator=denominator+2;
        flag=-flag;
        sum=sum+item;
    }
    printf("sum=%lf\n",sum);

    return 0;
}


循环 还是不怎么会

posted @ 2013-10-21 00:17  傻子疯子捏子  阅读(88)  评论(0编辑  收藏  举报