这段程序没有编错,可是算不出结果,请指点,屏幕上没有结果。 float f(float x) { float y; // y=(((0.54525/1e7-1.2103722/1e10*273.16)*x + 1.4307/1e7*273.16 - 0.75/1e4)*x + 0.57/1e4*273.16)*x-0.7; y=(0.54525/1e7-1.2103722/1e10*273.16)*x*x*x + (1.4307/1e7*273.16 - 0.75/1e4)*x*x + (0.57/1e4*273.16)*x;//-0.7; 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) { // 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); } main() { float x1=0,x2=70,f1,f2,x; do { f1=f(x1); f2=f(x2); } while(f1*f2>=0); x=root(x1,x2); printf("A root of equation is%f",x); while(1); } |