编程运行为0
#include<iostream.h>#include<math.h>doublearc(doublex){doublesum=0,a=x,b=1,c=1;while(...
#include<iostream.h>
#include<math.h>
double arc(double x)
{double sum=0,a=x,b=1,c=1;
while(fabs(c*a/b)<=1e-5)
{sum+=c*a/b;
c=(-1)*c;
a=a*x*x;
b+=2;
}
return sum;
}
void main()
{double pi;
pi=16*arc(1.0/5)-4*arc(1.0/239);
cout<<pi<<endl;
}求pi值(3.14159265)利用Arc(x)=x-x3/3+x5/5-x7/7+……直到绝对值不大于10(-5)次幂x3,x5,x7-----3,5,7为次幂 展开
#include<math.h>
double arc(double x)
{double sum=0,a=x,b=1,c=1;
while(fabs(c*a/b)<=1e-5)
{sum+=c*a/b;
c=(-1)*c;
a=a*x*x;
b+=2;
}
return sum;
}
void main()
{double pi;
pi=16*arc(1.0/5)-4*arc(1.0/239);
cout<<pi<<endl;
}求pi值(3.14159265)利用Arc(x)=x-x3/3+x5/5-x7/7+……直到绝对值不大于10(-5)次幂x3,x5,x7-----3,5,7为次幂 展开
1个回答
2010-04-18
展开全部
while(fabs(c*a/b)<=1e-5)
改为while(fabs(c*a/b)>1e-5)
试试吧!
改为while(fabs(c*a/b)>1e-5)
试试吧!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询