用如下公式求
#include <iostream>
using namespace std;
int main( )
{
int n,sign;
double total,f;
n=1;
total=0;
sign=1;
f=1; //用f代表待累加的每一项的绝对值
while(f>1e-5)
{
total+=(sign*f);
n+=2;
f=1.0/n;
sign*=-1; //sign变号
}
cout<<"total="<<4*total<<endl;
return 0;
}原文:http://blog.csdn.net/sxhelijian/article/details/50825627