haha1235  
#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 on 2013-10-07 21:37  haha1235  阅读(88)  评论(0编辑  收藏  举报