Advertisement
rootuss

1/x

Feb 20th, 2017
441
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 <cmath>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. double F(double x)
  8. {
  9.     return 1/x;
  10. }
  11.  
  12. double oblicz(double p, double q, int n)
  13. {
  14.     double dl=(q-p)/n, s=0;
  15.  
  16.     for(int i=0;i<n;i++)
  17.     {
  18.         s+=abs(F(p+dl*i+dl/2));
  19.     }
  20.     return dl*s;
  21. }
  22.  
  23. int main()
  24. {
  25.     int n;
  26.     int stopien;
  27.     double p,q;
  28.     cout<< "Podaj na ile fragmentow chcesz podzielic obliczane pole"<<endl;
  29.     cin>>n;
  30.     cout<<"Podaj p:"<<endl;
  31.     cin>>p;
  32.     cout<<"Podaj q:"<<endl;
  33.     cin>>q;
  34.  
  35.     cout<<oblicz(p, q, n);
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement