vertc

12-12

Dec 12th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. float F(float x) {
  7.     return (x*x)-x-3;
  8. }
  9.  
  10. int main() {
  11.     long double p, q, e1, s;
  12.     cout<<"Podaj wartosc p: ";
  13.     cin>>p;
  14.     cout<<"Podaj wartosc q: ";
  15.     cin>>q;
  16.     cout<<"Podaj wartosc E1: ";
  17.     cin>>e1;
  18.     s = (p+q)/2;
  19.     while (F(q) != 0 && (q-p) >= e1) {
  20.         s = (p+q)/2;
  21.         if(F(p) * F(s) > 0) {
  22.             p = s;
  23.         }
  24.         else  {
  25.             q = s;
  26.         }
  27.     }
  28.     if (F(p) == 0) {
  29.         cout<<"p wynosi: "<<p;
  30.         return 0;
  31.     }
  32.     if (F(q) == 0) {
  33.         cout<<"q wynosi: "<<q;
  34.         return 0;
  35.     }
  36.     cout<<"Miejsce zerowe wynosi: "<<s;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment