Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. //wyznaczanie miejsca zerowego funkcji w przedziale [p, q]
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double F (double x)
  7. {
  8.  return pow(x,2)-x-3;
  9. }
  10.  
  11. double oblicz (double p, double q, double E1)
  12. {
  13.  double s=(p+q)/2;
  14.  while (F(p)!=0 && F(q)!=0 && q-p>=E1)
  15.  {
  16.   s=(p+q)/2;
  17.   if (F(p)*F(s)>0) p=s; else q=s;
  18.  }
  19.  if (F(p)==0) return p;
  20.  if (F(q)==0) return q;
  21.  return s;
  22.  cout<<"s= "<<s<<endl;
  23. }
  24.  
  25. main()
  26. {
  27.  double p, q, E1;
  28.  cout<<"podaj przedzial [p, q]: ";
  29.  cin>>p>>q;
  30.  cout<<"podaj dokladnosc E1: ";
  31.  cin>>E1;
  32.  cout<<"miejsce zerowe = "<<oblicz(p,q,E1)<<endl;
  33. //system("pause");
  34.  return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement