
求高手,,C语言弦截法方程的根,
#include<math.h>#include<stdio.h>floatf(floatx){return((x-5)*x+16)*x-80;}floatxpoint(...
#include <math.h>
#include <stdio.h>
float f(float x)
{
return ((x-5)*x+16)*x-80;
}
float xpoint(float x1,float x2)
{
return (x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));
}
float root(float x1,float x2)
{
float x,y,y1,y2;
y1=f(x1);y2=f(x2);
do
{
x=xpoint(x1,x2);
y=f(x);
if(y*y1>0) {y1=y;x1=x;}
else {x2=x;y2=y;}
} while (fabs(y)>0.00001);
return x;
}
void main()
{
float x,x1,x2,y1,y2;
do
{ printf("input x1,x2:");
scanf("%f,%f",&x1,&x2);
y1=f(x1);
y2=f(x2);
} while(y1*y2>0);
x=root(x1,x2);
printf("A root is %f\n",x);
} 展开
#include <stdio.h>
float f(float x)
{
return ((x-5)*x+16)*x-80;
}
float xpoint(float x1,float x2)
{
return (x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));
}
float root(float x1,float x2)
{
float x,y,y1,y2;
y1=f(x1);y2=f(x2);
do
{
x=xpoint(x1,x2);
y=f(x);
if(y*y1>0) {y1=y;x1=x;}
else {x2=x;y2=y;}
} while (fabs(y)>0.00001);
return x;
}
void main()
{
float x,x1,x2,y1,y2;
do
{ printf("input x1,x2:");
scanf("%f,%f",&x1,&x2);
y1=f(x1);
y2=f(x2);
} while(y1*y2>0);
x=root(x1,x2);
printf("A root is %f\n",x);
} 展开
1个回答
展开全部
#include <math.h>
#include <stdio.h>
float f(float x)
{
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,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.00001);
return x;
}
void main()
{
float x,x1,x2,f1,f2;
do
{
printf("input x1,x2:");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f2=f(x2);
}while(f1*f2>=0);
x=root(x1,x2);
printf("A root is %f\n",x);
}
#include <stdio.h>
float f(float x)
{
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,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.00001);
return x;
}
void main()
{
float x,x1,x2,f1,f2;
do
{
printf("input x1,x2:");
scanf("%f,%f",&x1,&x2);
f1=f(x1);
f2=f(x2);
}while(f1*f2>=0);
x=root(x1,x2);
printf("A root is %f\n",x);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2024-10-22 广告
百事牛是共享提供商,我们提供可靠有效的服务,适当合理的授权费有利于的继续更新优化。同样的事情,同样的方法,百事牛团队十年磨一剑,始终至聚焦在密码恢复领域,深耕于此,我们已研制出有别于其他公司的算法和运算模式, 百事牛的暴力模式加入了分布式点...
点击进入详情页
本回答由百事牛提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询