C语言 弦截法

来源:百度知道 编辑:UC知道 时间:2024/06/07 01:03:57
大家可以帮我看看下面这代码错在哪么??
软件老提示我有句法错误,但是错在什么地方,我老是不清楚?
#include<stdio.h>
#include<math.h>
void main()
{
float f(float x);//函数:求f(x)=x*x*x-5x*x+16*x-80的函数值//
float jiaodian(float a,float b,float c,float d);//函数:求x1,x2两点连线与x轴的交点//
float x1,x2,f1,f2;
float x,y;//x1,x2两点连线与x轴的交点变量,还有其对应的函数值//
printf("请输入x1,x2的值:\n");
do
{
scanf("%d,%d",&x1,&x2);
f1=f(x1);
f2=f(x2);
}
while(f1*f2>=0);
do
{
x=jiaodian(x1,x2,f1,f2);
y=f(x);
if(y*f1>=0)
{
f1=y;
x1=x;
}
else
{
f2=y;
x2=x;
}
while(fabs(y)>0.0001);
printf("该函数与x轴的交点:%f",x);
}
float f(float x)
{
float y;
y=((x-5)*x+16)*x-80;
return y;
}
float jiaodian(float a,float b,float c,float d)
{
float jiaodian;
jiaodian=(a*b-b*c)/(d-c

看不懂。。。

do
{
x=jiaodian(x1,x2,f1,f2);
y=f(x);
if(y*f1>=0)
{
f1=y;
x1=x;
}
else
{
f2=y;
x2=x;
}
}--------------->你这里少一个括上。。。
while(fabs(y)>0.0001);

求f(x)=x*x*x-5x*x+16*x-80的函数值//
这里5X是不是5*X啊??

scanf("%d,%d",&x1,&x2);
输入语句中不要有分隔符号“,”,这样可能会造成输入数据时错误。
do
{
x=jiaodian(x1,x2,f1,f2);
y=f(x);
if(y*f1>=0)
{
f1=y;
x1=x;
}
else
{
f2=y;
x2=x;
}
while(fabs(y)>0.0001);
少了一个右大括号。循环体没有封闭。