fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. double f(double x){
  5. return((x-1)*(x-1)*sin(x));
  6. }
  7. int main() {
  8. double a=-6,b=9,eps=0.000000001,c,d;
  9. while(b-a>eps){
  10. c=a+(b-a)/3.0;
  11. d=b-(b-a)/3.0;
  12. if(f(c)<f(d))b=d;
  13. else a=c;
  14. }
  15. cout<<(a+b)/2;
  16. return 0;
  17. }
  18.  
  19.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
5.16049