Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define error .000005
  4. double f(double x)
  5. {
  6.     double r;
  7.     r=sqrt(1.0-(x*x));
  8.     return r;
  9. }
  10.  
  11. void Calculation(double a,double b)
  12. {
  13.     double
  14.  
  15.      n=5,sum=0,ans=0,ans1;
  16.     do{
  17.         ans1=ans;
  18.         sum=0;
  19.         double delx = (b-a)/n;
  20.         for(int i=0;i<=n;i++)
  21.         {
  22.             double xx = a + (i*delx); /// x0 = a; x1= a + delx; x2= a + delx + delx;  x3= a + delx + delx + delx;........
  23.             if(i==0 || i==n)          /// x0 = a; x1= a + delx; x1= a + 2*delx;       x1= a + 3*delx;....................
  24.                 sum +=  f(xx);
  25.            else if (i % 2 != 0)
  26.                 sum+= 4 * f(xx);
  27.            else
  28.                 sum+= 2 * f(xx);  
  29.         }
  30.          ans = 0.5 * delx * sum;
  31.         cout<<"When n = "<<n<<" then Area = "<<ans<<endl;
  32.         n+=5;
  33.     }while(abs(ans1-ans)>error);
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.  Calculation(0,1);
  40.  return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement