Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double Fa(double x) {
  6. return pow(x,3)+5*x-3;
  7. }
  8.  
  9. main() {
  10. double p = -2, q=2, L = 100;
  11. double s = (p+q)/2;
  12. do {
  13. L--;
  14. s=(p+q)/2;
  15. if(Fa(p)*Fa(s)>0) {
  16. p=s;
  17. } else {
  18. q=s;
  19. }
  20.  
  21. } while(Fa(p) != 0 && Fa(q) != 0 && L>0);
  22. if(Fa(p) == 0 || Fa(q) == 0) {
  23. cout<<p;
  24. exit(123);
  25. }
  26. cout<<"S: "<<s;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement