Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- float f(float x)
- {
- return 2*x-4;
- }
- float mz(float a, float b, float d)
- {
- float dokl;
- while(f(a)!=0&&f(b)!=0&&b-a>d)
- {
- dokl=(a+b)/2;
- if(f(a)*f(dokl)>0)
- a=dokl;
- else
- b=dokl;
- }
- if(f(a)==0)
- return a;
- if(f(b)==0)
- return b;
- return dokl;
- }
- int main()
- {
- float l,p,dok;
- do
- {
- cout<<"podaj lewy kraniec przedzialu: ";
- cin>>l;
- cout<<"podaj prawy kraniec przedzialu: ";
- cin>>p;
- }
- while(f(l)*f(p)>0||l>=p);
- cout<<"podaj dokladnosc: ";
- cin>>dok;
- cout<<"miejsce zerowe wynosi: "<<mz(l,p,dok);
- return 0;
- }
Add Comment
Please, Sign In to add comment