Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double Fa(double x) {
- return pow(x,3)+5*x-3;
- }
- main() {
- double p = -2, q=2, L = 100;
- double s = (p+q)/2;
- do {
- L--;
- s=(p+q)/2;
- if(Fa(p)*Fa(s)>0) {
- p=s;
- } else {
- q=s;
- }
- } while(Fa(p) != 0 && Fa(q) != 0 && L>0);
- if(Fa(p) == 0 || Fa(q) == 0) {
- cout<<p;
- exit(123);
- }
- cout<<"S: "<<s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement