Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double F(double x) {
- return x*x*x + 5*x - 3;
- // return x*x*x - 8;
- // return x*x - 4;
- }
- float input (string msg) {
- cout << msg;
- float x;
- cin >> x;
- return x;
- }
- int main()
- {
- float p = -2,
- q = 2,
- E1 = 0.0001,
- s;
- p = input("Podaj p: ");
- q = input("Podaj q: ");
- E1 = input("Podaj E1: ");
- s = (p + q) / 2;
- while (F(p) != 0 && F(q) != 0 && q - p >= E1) {
- s = (p + q) / 2;
- if (F(p) * F(s) > 0) {
- p = s;
- } else {
- q = s;
- }
- }
- if (F(p) == 0) {
- cout << p << endl;
- return 0;
- } else if (F(q) == 0) {
- cout << q << endl;
- return 0;
- }
- cout << "Wynik: " << s << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement