c程序设计第四版谭浩强
用二分法求下面方程在(-10,10)之间的根:
2x3-4x2+3x-6=0
以下是此题的【c源代码】,需要【c++源代码】请点击进入
#include <stdio.h>
#include <math.h>
int main()
{float x0,x1,x2,fx0,fx1,fx2;
do
{printf("enter x1 & x2:");
scanf("%f,%f",&x1,&x2);
fx1=x1*((2*x1-4)*x1+3)-6;
fx2=x2*((2*x2-4)*x2+3)-6;
}while(fx1*fx2>0);
do
{x0=(x1+x2)/2;
fx0=x0*((2*x0-4)*x0+3)-6;
if ((fx0*fx1)<0)
{x2=x0;
fx2=fx0;
}
else
{x1=x0;
fx1=fx0;
}
}while(fabs (fx0)>=1e-5);
printf("x=%6.2f\n",x0);
return 0;
}
本文链接:http://www.wb98.com/c/post/tanhaoqiang_5.15.html
本站文章搜索: