用弦截法求解一元三次方程的根(利用c语言实现)

#include<stdio.h>#include<math.h>floatf(x){floata,b,c,d;floaty;printf("Pleaseinputa,b... #include<stdio.h>
#include<math.h>
float f(x)
{
float a,b,c,d;
float y;
printf("Please input a,b,c,d:\n");
scanf("%f,%f,%f,%f",&d,&d,&d,&d);
y=((a*x+b)*x+c)*x+b;
return (y);
}
float xpoint(x1,x2)
{
float y,x;
y=(x1*f(x2)-x2*f(x1))/(f(x)-f(x1));
return (y);
}
float x1,x2;
{
int i;
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.000001);
rerurn(x);
}
main()
{
float x1,x2,f1,f2,x;
do
{
printf("Please input x1,x2:\n");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f1=f(x2);
}
while(f(f1*f2)>=0);
x=root(x1,x2);
printf("A root of the eauation is %8.2f",x);
}
错误提示:
--------------------Configuration: 45 - Win32 Debug--------------------
Compiling...
45.C
G:\45.C(15) : error C2065: 'x' : undeclared identifier
G:\45.C(19) : error C2449: found '{' at file scope (missing function header?)
G:\45.C(37) : error C2059: syntax error : '}'
执行 cl.exe 时出错.

45.exe - 1 error(s), 0 warning(s)
请问各位高手,怎么解决?急需
#include<stdio.h>
#include<math.h>
float f(float x)
{
float a,b,c,d;
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);
}
void main()
{
float x1,x2,f1,f2,x;
float a,b,c,d;
printf("Please input a,b,c,d:\n");
scanf("%f,%f,%f,%f",&d,&d,&d,&d);
do
{
printf("Please input x1,x2:\n");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f1=f(x2);
}
while(f(f1*f2)>=0);
x=root(x1,x2);
printf("A root of the eauation is %8.4f\n",x);
}
这是重新修改的,不过还是没法运行!请各位指教!
展开
 我来答
風随風
推荐于2017-12-16 · 超过14用户采纳过TA的回答
知道答主
回答量:36
采纳率:0%
帮助的人:40.8万
展开全部
我只看了你的第二个
你定义的f函数只有一个形参x,所以在main函数中输入的你所认为的实参abcd 的值无法转给f函数 所以运行时会出错 只要赋给abcd确定的值或增加f函数的形参
scanf("%f,%f,%f,%f",&d,&d,&d,&d);这句也错了应该是scanf("%f,%f,%f,%f",&a,&b,&c,&d);
sh00p1
2009-10-15 · 超过14用户采纳过TA的回答
知道答主
回答量:35
采纳率:0%
帮助的人:42.2万
展开全部
试下这个,我是直接给abcd指定值了,
如果要传a b c d 要改f()和xpoint()的参数
float f(float x,float a,float b,float c,float,d)
float xpoint(float x1,floatx2,float a,float b,float c,float,d)
#include <math.h>
main()
{
float root(float x1, float x2);
float f(float x);
float xpoint(float x1,float x2);
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);
getch();
}
float root(float x1, float x2)
{
int i;
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);
}
float f(float x)
{
float y;
y=((x-5.0)*x+16)*x-80;
return (y);
}
float xpoint(float x1,float x2)
{
float y;
y=(x1*f(x2)-x2*f(x1)) / (f(x2) - f(x1));
return (y) ;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友06329ccc9
2009-10-10 · TA获得超过1952个赞
知道小有建树答主
回答量:533
采纳率:100%
帮助的人:531万
展开全部
改成下面的:
#include<stdio.h>
#include<math.h>
float a,b,c,d;
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.000001);
return(x);
}
void main()
{
float x1,x2,f1,f2,x;
printf("Please input a,b,c,d:\n");
scanf("%f,%f,%f,%f",&a,&b,&c,&d);

do
{
printf("Please input x1,x2:\n");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f2=f(x2);
}
while(f(f1*f2)>=0);
x=root(x1,x2);
printf("A root of the eauation is %8.4f\n",x);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式