fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. double f(double x){return 2*x*x*x+3*x-1;}
  4. int main(){
  5. double a=0,b=1,mid,tol=1e-8;
  6. while(fabs(b-a)>tol){
  7. mid=(a+b)/2;
  8. if(f(a)*f(mid)<0)b=mid;
  9. else a=mid;
  10. }
  11. cout<<setprecision(10)<<fixed<<mid;
  12. }
  13.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
0.3129084036