Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Vi du ve bai toan tim kiem nhi phan
- #include <iostream>
- using namespace std;
- float x;
- float f(float x){
- return x*x*x + x - 1;
- }
- int main(){
- float l = -5, r = 5, eps = 1e-5;
- while(r - l > eps){
- float mid = (r + l) / 2;
- if (f(mid) > 0) r = mid;
- else l = mid;
- }
- cout << "Nghiem la " << (r + l) / 2 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment