帮忙看下程序,实在检查不出错误……
二分法求两方程的根检查语法没错
我新来的,多多照顾
#include<stdio.h>
#include<math.h>
float root (float x1,float x2,double (*f)(double))
{
float x=0;
do
{ x=(x1+x2)/2.0;
if (f(x)*f(x2)>=0)
x1=x;
else x2=x;
}
while (fabs(f(x))>=1e-5);
return x;
}
double f1 (double x)
{
return sin(2*x+1);
}
double f2 (double x)
{
return x*x*x-5*x*x+16*x-80;
}
void main ()
{
double y1,y2;
y1=root (-1,3,f1);
y2=root (2,6,f2);
printf("%.2f\n",y1);
printf("%.2f\n",y2);
}