fork download
  1. #include <iostream>
  2.  
  3. #include <math.h>
  4. #define eps 0.01
  5. using namespace std;
  6.  
  7. float f( double x)
  8. {
  9. return pow(x,3)-12*x+9;
  10. }
  11.  
  12. double injum(double a, double b)
  13. {
  14. double c=(a+b)/2;
  15. if (b-a< eps) return c;
  16. else
  17. {
  18. if(f(c)*f(a)<0) return injum(a,c);
  19. else return injum(b,c);
  20. }
  21.  
  22. }
  23. int main()
  24. {
  25. cout<<"introduceti a:";
  26. int a;cin>>a;
  27. cout<<"introduceti b:";
  28. int b;cin>>b;
  29. cout<<"solutia cu eroarea eps=0.01 este"<<injum(a,b);
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 3344KB
stdin
2
-2
stdout
introduceti a:introduceti b:solutia cu eroarea eps=0.01 este0