Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define error .000005
- double f(double x)
- {
- double r;
- r=sqrt(1.0-(x*x));
- return r;
- }
- void Calculation(double a,double b)
- {
- double
- n=5,sum=0,ans=0,ans1;
- do{
- ans1=ans;
- sum=0;
- double delx = (b-a)/n;
- for(int i=0;i<=n;i++)
- {
- double xx = a + (i*delx); /// x0 = a; x1= a + delx; x2= a + delx + delx; x3= a + delx + delx + delx;........
- if(i==0 || i==n) /// x0 = a; x1= a + delx; x1= a + 2*delx; x1= a + 3*delx;....................
- sum += f(xx);
- else if (i % 2 != 0)
- sum+= 4 * f(xx);
- else
- sum+= 2 * f(xx);
- }
- ans = 0.5 * delx * sum;
- cout<<"When n = "<<n<<" then Area = "<<ans<<endl;
- n+=5;
- }while(abs(ans1-ans)>error);
- }
- int main()
- {
- Calculation(0,1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement