#include<iostream>
#include<cmath>
using namespace std;
int main( )
{int a=1;
double b=1,c=1,pi=0;
while(fabs(c)>=0.000001)
{pi+=c;
b+=2;
a=-a;
c=a/b;
}
pi=4*pi;
cout<<"pi="<<pi<<endl;
return 0;
}
运行结果:
pi=3.14159
Press any key to continue