c++用二分法求出方程e^x+10x-2=0的实根,误差不得超过1/2*10^-2,运行结果空白,但是没有发现错误
#include<iostream>#include<cmath>usingnamespacestd;voidmain(){doublefunction(double);...
#include<iostream>
#include<cmath>
using namespace std;
void main()
{
double function(double);
double x1=0,x2=1,x0;
do
{
x0=(x1+x2)/2;
function(x0);
if(function(x1)*function(x0)<0)
{
x2=x0;
}
else
{
x1=x0;
}
}while((x2-x1)>=(1/2)*pow(10,-2));
cout<<"the result is:"<<x0<<endl;
}
double function(double x)
{
return(exp(x)+10*x-2);
} 展开
#include<cmath>
using namespace std;
void main()
{
double function(double);
double x1=0,x2=1,x0;
do
{
x0=(x1+x2)/2;
function(x0);
if(function(x1)*function(x0)<0)
{
x2=x0;
}
else
{
x1=x0;
}
}while((x2-x1)>=(1/2)*pow(10,-2));
cout<<"the result is:"<<x0<<endl;
}
double function(double x)
{
return(exp(x)+10*x-2);
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询