4-1

#include<stdio.h>

#include<math.h>

int main(void)

{

         int denominator,flag;

         double item,pi;

 

         flag=1;

         denominator=1;

         item=1.0;

         pi=0;

 

         while(fabs(item)>=0.0001){

                   item=flag*1.0/denominator;

                   pi=pi+item;

                   flag=-flag;

                   denominator=denominator+2;

         }

         pi=pi*4;

         printf("pi=%.4f\n",pi);

 

         return 0;

}

posted @ 2013-10-04 18:11  zhaoyang16  阅读(132)  评论(0编辑  收藏  举报