#include <stdio.h>#include <stdlib.h>
double binary_search(double lower,double upper,double y);
int main(){ double lower=-10000,upper=10000,y; while (scanf("%lf",&y)==1){ if (binary_search(lower+0.000001,upper-0.000001,y)==10001) printf("NULL\n"); else printf("%.4lf\n",binary_search(lower+0.000001,upper-0.000001,y)); } system("pause"); return 0;}
double binary_search(double lower,double upper,double y){ double mid,temp1,temp2; while (lower<=upper){ mid=(lower+upper)/2.0; if (2.0*mid*mid*mid-4.0*mid*mid+3.0*mid-6.0<y) lower=mid+0.000001; if (2.0*mid*mid*mid-4.0*mid*mid+3.0*mid-6.0>y) upper=mid-0.000001; else return mid; } return 10001;}//函数2x^3-4x^2+3x-6为单调递增 求指导 为什么无论我输入什么输出都是0.000?谢谢
double binary_search(double lower,double upper,double y);
int main(){ double lower=-10000,upper=10000,y; while (scanf("%lf",&y)==1){ if (binary_search(lower+0.000001,upper-0.000001,y)==10001) printf("NULL\n"); else printf("%.4lf\n",binary_search(lower+0.000001,upper-0.000001,y)); } system("pause"); return 0;}
double binary_search(double lower,double upper,double y){ double mid,temp1,temp2; while (lower<=upper){ mid=(lower+upper)/2.0; if (2.0*mid*mid*mid-4.0*mid*mid+3.0*mid-6.0<y) lower=mid+0.000001; if (2.0*mid*mid*mid-4.0*mid*mid+3.0*mid-6.0>y) upper=mid-0.000001; else return mid; } return 10001;}//函数2x^3-4x^2+3x-6为单调递增 求指导 为什么无论我输入什么输出都是0.000?谢谢