Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. float f (float x){
  7. return (5*x*x*x*x*x-4*x*x*x*x+3*x*x*x-2*x*x+x-1);
  8. }
  9. float ff (float x){
  10. return(pow(2,x)-10);
  11. }
  12. float a,b,d;
  13. int main()
  14. {
  15. /* cin >> a >> b >> d;
  16. if(f(a)==0)
  17. {
  18. cout << a<< " "<< f(a); return 0;
  19. }
  20. if(f(b)==0)
  21. {
  22. cout << b<< " " << f(b); return 0;
  23. }
  24.  
  25. while (b-a>d)
  26. {
  27. float sr = (a+b)/2;
  28. if(f((a+b)/2)==0)
  29. {
  30. cout << (a+b)/2 << " "<< f(sr); return 0;
  31. }
  32. if(f(a)*f(sr)<0)b=sr;
  33. else a = sr;
  34. }
  35. cout << (a+b)/2<<" " <<f((a+b)/2);
  36. */
  37. cin >> a >> b >> d;
  38. if(f(a)==0)
  39. {
  40. cout << a<< " "<< f(a); return 0;
  41. }
  42. if(ff(b)==0)
  43. {
  44. cout << b<< " " << ff(b); return 0;
  45. }
  46.  
  47. while (b-a>d)
  48. {
  49. float sr = (a+b)/2;
  50. if(ff((a+b)/2)==0)
  51. {
  52. cout << (a+b)/2 << " "<< ff(sr); return 0;
  53. }
  54. if(ff(a)*ff(sr)<0)b=sr;
  55. else a = sr;
  56. }
  57. cout << (a+b)/2<<" " <<ff((a+b)/2);
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement