Advertisement
Guest User

rekurencja

a guest
Sep 16th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. const double E=0.000000001;
  7. double f(double);
  8. double zerowe(double, double);
  9.  
  10. int main() {
  11. int a, b;
  12. cout<<"LICZENIE MIEJSC ZEROWYCH"<<endl;
  13. cout<<""<<endl;
  14. cout<<"PODAJ PRZEDZIAL: "<<endl;
  15. cout<<"a: ";
  16. cin>>a;
  17. cout<<"b: ";
  18. cin>>b;
  19.  
  20. cout<<zerowe(a,b);
  21. }
  22.  
  23. double zerowe(double a, double b){
  24. double x;
  25.  
  26.  
  27. if(abs(a-b)>=E){
  28.  
  29.  
  30.     double x=(a+b)/2;
  31.  
  32.  
  33.     if(f(a)*f(x)<=0)
  34.     {
  35.         return zerowe(a,x);
  36.     }else{
  37.         return zerowe(x,b);
  38.              }
  39.     }
  40.  
  41.  
  42.  
  43. return x;
  44.     }
  45.  
  46.     double f(double x)
  47.     {
  48.        return pow(x-2,3);
  49.        }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement