double arctan(double x)
{ int i;
double r,e,f,sqr;
sqr=x*x;
r=0; e=x; i=1;
while(e/i>1e-15)
{
f=e/i;
r=(i%4==1)? r+f : r-f;
e=e*sqr; i+=2;
}
return r;
}
#include<iostream.h>
int main()
{
double a,b;
double arctan(double x);//
函数原型声明
a=16.0*arctan(1/5.0);
b=4.0*arctan(1/239.0);
//
注意:因为整数相除结果取整,
//
如果参数写
1/5
,
1/239
,结果就都是
0
cout<<"PI="<<a-b<<endl;
}