Advertisement
aimon1337

f(x)=y

Jan 29th, 2020
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include<iostream>
  2. #include <math.h>
  3. #include <conio.h>
  4. using namespace std;
  5. float y;
  6. float f(float x)
  7. { return sin(x)+sin(2*x)+x;
  8. }
  9.  
  10. float DEI(float s, float d)
  11. {
  12.    if(d-s<=0.0000001) return s;
  13.    else
  14.    { float m=(s+d)/2;
  15.      if(f(m)==y) return m;
  16.      else if(f(m)<y) return DEI(m,d);
  17.           else return DEI(s,m);
  18.    }
  19. }
  20.  
  21. int main()
  22. {
  23.     cin>>y;
  24.     cout.precision(8);
  25.     cout<<DEI(0,1);
  26. //  system("pause");
  27.     getch();
  28.   return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement