c语言,二分法求根无论我输入什么都是error.#include#includedouble fun(double x){return 1.0*x*x-10;}int main(){double x1,x2;if ((scanf("%f,%f",&x1,&x2)!=0)&&(fun(x1)*fun(x2)>=0)&&(x10)x2=(x1+x2)/2 ;continue;if(fun((x1+x2)/2)=1E-6||(fabs(f
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 15:00:46
c语言,二分法求根无论我输入什么都是error.#include#includedouble fun(double x){return 1.0*x*x-10;}int main(){double x1,x2;if ((scanf("%f,%f",&x1,&x2)!=0)&&(fun(x1)*fun(x2)>=0)&&(x10)x2=(x1+x2)/2 ;continue;if(fun((x1+x2)/2)=1E-6||(fabs(f
c语言,二分法求根
无论我输入什么都是error.
#include
#include
double fun(double x)
{return 1.0*x*x-10;}
int main()
{double x1,x2;
if ((scanf("%f,%f",&x1,&x2)!=0)&&(fun(x1)*fun(x2)>=0)&&(x10)
x2=(x1+x2)/2 ;continue;
if(fun((x1+x2)/2)=1E-6||(fabs(fun(x2))>=1E-6));
printf("%f\t%f",x1,x2);
printf("%f\t%f",fun(x1),fun(x2));}
else
printf("error!\n");
return 0;
c语言,二分法求根无论我输入什么都是error.#include#includedouble fun(double x){return 1.0*x*x-10;}int main(){double x1,x2;if ((scanf("%f,%f",&x1,&x2)!=0)&&(fun(x1)*fun(x2)>=0)&&(x10)x2=(x1+x2)/2 ;continue;if(fun((x1+x2)/2)=1E-6||(fabs(f
#include
#include
double fun(double x)
{return 1.0*x*x-10;}
int main()
{double x1,x2;
//此处有两个错误,double 类型的输入输出格式是lf,判断条件是x1x2处的函数值异号而不是同号
if ((scanf("%lf,%lf",&x1,&x2))&&(fun(x1)*fun(x2)0)
{x2=(x1+x2)/2 ;continue;}
}
//循环条件也有问题,当某一个端点的值足够小时就表示找到了,就要退出循环
while (!(fabs(fun(x1))