C程序编译时提示错误,怎么改正下列程序呢?找不出错误在哪里,怎么改?
/*用弦截法求方程f(x)=x^3-5x^2+16x-80的根。方法如下。*/#include<stdio.h>#include<math.h>floatf(floatx...
/*用弦截法求方程f(x)=x^3-5x^2+16x-80的根。方法如下。*/
#include<stdio.h>
#include<math.h>
float f(float x) /*定义了f函数,*/
{
float y;
y=((x-5.0)*x+16.0)*x-80.0;
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,floatx2)
{
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);
}
void main() /*主函数main()*/
{
float x1,x2,f1,f2,x;
do
{
printf("input x1,x2:\n");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f2=f(x2);
}
while(f1*f2>=0);
x=root(x1,x2);
printf("A root of equation is %8.4f\n",x);
} 展开
#include<stdio.h>
#include<math.h>
float f(float x) /*定义了f函数,*/
{
float y;
y=((x-5.0)*x+16.0)*x-80.0;
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,floatx2)
{
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);
}
void main() /*主函数main()*/
{
float x1,x2,f1,f2,x;
do
{
printf("input x1,x2:\n");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f2=f(x2);
}
while(f1*f2>=0);
x=root(x1,x2);
printf("A root of equation is %8.4f\n",x);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询