俺是菜鸟,求哪位高手帮我看一下这个程序
好象函数F调用不起作用.
#include<stdio.h> #include<math.h> #include<conio.h> #define eps 1e-1 float f1(float,float,float(*f)(float)); float f(float); float n,d[5]; main() {float a,b; float x; printf("Enter the n:\n"); scanf("%f",&n); if(n<=5) printf("Enter the a,b:\n"); scanf("%f%f",&a,&b); clrscr(); x=f1(a,b,f); printf("\nThe root of the equation is %f",x); } float f(float x) { float s; for(s=0;n>=0;n--) {s+=d[n]*pow(x,n);} return s; } float f1(float a,float b,float(*f)(float))
{ float c,fc,fa=f(a),fb=f(b); int k=1; printf("k\t c\t f(x)\n"); while(1) {if(fa*fb>0) exit(); c=(a+b)/2,fc=f(c); if(fabs(fc)<eps)break; else if(fa*fc<0){b=c;fb=fc;} else {a=c;fa=fc;} if(b-a<eps) break; printf("%d\t\t%f\t\t%f\n",k++,c,fc);} return c; }