Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- double f(double x)
- {
- return (1/(1+(x*x)));
- }
- int main()
- {
- double a,b,n,sum=0,h,ans,x,i;
- cin>>a>>b>>n;
- h=((b-a)/n);
- for(i=1;i<=n-1;i++)
- {
- x=a+h*i;
- sum=sum+2*f(x);
- }
- sum=sum+f(a)+f(b);
- ans=sum*(h/2);
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement