求一个二分法的c程序
求8*X*x*x*x+7*x*x*x+2*x*x+3*x+6-Y;用二分法;输入Y;求x;的c程序x>=0,x<=100;
回复 2楼 rjsp
求助,#include<stdio.h>#include<math.h>
#include<stdlib.h>
int main()
{
double x0,x1,x2,fx0,fx1,fx2,Y,k=0;
x1=0;x2=100;
scanf("%lf",&Y);
fx1=8*x1*x1*x1*x1+7*x1*x1*x1+2*x1*x1+3*x1+6-Y;
fx2=8*x2*x2*x2*x2+7*x2*x2*x2+2*x2*x2+3*x2+6-Y;
do
{
x0=(x1+x2)/2;
fx0=8*x0*x0*x0*x0+7*x0*x0*x0+2*x0*x0+3*x0+6-Y;
if((fx0*fx1)<0)
{
x2=x0;
fx2=fx0;
}
else
{
x1=x0;
fx1=fx0;
}k++;
}while(fabs(fx0)>=0.0001);
if(k==0)
printf("No souition");
else
printf("x= %.4lf",x0);
return 0;
}