《c语言用弦截法求方程》由会员分享,可在线阅读,更多相关《c语言用弦截法求方程(2页珍藏版)》请在金锄头文库上搜索。
/用弦截法求方程飞f(x)=x*x*x-5*x*x+16*x-80=0#include#includefloat f(float x)float y;y=(x-5.0)*x+16.0)*x-80.0;return y;float xpoint(float x1,float x2)float x;x=(x*f(x2)-x2*f(x1)/(f(x2)-f(x1);return x;float root(float x1,float x2)float x,y,y1;y1=f(x1);dox=xpoint(x1,x2);y=f(x);if(y*y10)y1=y;x1=x;elsex2=x;while(fabs(y)=0.0001);return x;void main()float x1,x2,f1,f2,x;doprintf(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.4n,x);