发布网友 发布时间:2022-04-25 21:48
共1个回答
热心网友 时间:2022-06-17 20:19
#include<stdio.h>
#include<math.h>
float a,b,c,d;
float f(float x);
float xpoint(float x1,float x2);
float root(float x1,float x2);
void main()
{float x1,x2,f1,f2,x;
do
{printf("input a b c d x1 x2 :\n");
scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&x1,&x2);
f1=f(x1);
f2=f(x2);
}while(f1*f2>=0);
x=root(x1,x2);
printf("a root of equation is %8.4f",x);
}
float f(float x)
{
float y;
y=((a*x+b)*x+c)*x+d;
return(y);
}
float xpoint(float x1,float x2)
{
float y;
y=(x1*f(x2)-x2*f(x1)/f(x2)-f(x1));
return (y);
}
float root(float x1,float x2)
{
float x,y,y1;
y1=f(x1);
do
{
x=xpoint (x1,x2);
y=f(x);
if (y*y1>0)
{y1=y;
x1=x;}
else x2=x;
}while(fabs(y)>=0.0001);
return(x);
}
可以运行了