5-3

#include<stdio.h>
#include<math.h>
int main(void)
{
    double e,pi;
    double funpi(double e);

    printf("Enter e:");
    scanf("%lf",&e);
    pi=funpi(e);
    printf("pi=%f\n",pi);

    return 0;
}

double funpi(double e)
{
    int denominator,flag;
    double item,sum;

    flag=1;
    denominator=1;
    item=1.0;
    sum=0;

    while(fabs(item)>=e){
        item=flag*1.0/denominator;
        sum=sum+item;
        flag=-flag;
        denominator=denominator+2;
    }

    return sum*4;
}

posted @ 2013-10-07 23:36  傻子疯子捏子  阅读(103)  评论(0编辑  收藏  举报