Guest User

Untitled

a guest
Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. float f(float x)
  6. {
  7. return 2*x-4;
  8. }
  9.  
  10. float mz(float a, float b, float d)
  11. {
  12. float dokl;
  13. while(f(a)!=0&&f(b)!=0&&b-a>d)
  14. {
  15. dokl=(a+b)/2;
  16. if(f(a)*f(dokl)>0)
  17. a=dokl;
  18. else
  19. b=dokl;
  20. }
  21. if(f(a)==0)
  22. return a;
  23. if(f(b)==0)
  24. return b;
  25. return dokl;
  26. }
  27.  
  28.  
  29.  
  30. int main()
  31. {
  32. float l,p,dok;
  33. do
  34. {
  35. cout<<"podaj lewy kraniec przedzialu: ";
  36. cin>>l;
  37. cout<<"podaj prawy kraniec przedzialu: ";
  38. cin>>p;
  39. }
  40. while(f(l)*f(p)>0||l>=p);
  41. cout<<"podaj dokladnosc: ";
  42. cin>>dok;
  43. cout<<"miejsce zerowe wynosi: "<<mz(l,p,dok);
  44.  
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment