Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #pragma hdrstop
  2. #pragma argsused
  3. #include <iostream.h>
  4. #include <math.h>
  5. #include <conio.h>
  6.  
  7. double f(double x)
  8. {
  9.     return exp(sin(x));
  10. }
  11. int main()
  12. {
  13.  
  14.     int n = 20;
  15.     double I = 0;
  16.     double I2 = 0;
  17.     double E;
  18.     cout << "E = ";
  19.     cin>>E;
  20.  
  21.     double h =  1.0/n;
  22.  
  23.     do{
  24.          I = I2;
  25.          I2 = 0;
  26.          h =  1.0/n;
  27.  
  28.          for (int i=0; i<n; i++)
  29.                 {
  30.                 I2+=f(i*h);
  31.                  }
  32.           I2 = I2*h;
  33.           n = n  * 2;
  34.        }
  35.     while ( fabs(I-I2) > E);
  36.    
  37.     cout<<n<<endl;
  38.     cout <<I<<endl;
  39.          
  40.     getch();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement