Created
February 2, 2020 16:08
-
-
Save MShirazAhmad/426950796ce18ad3ac70c74940e34d25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //TrapozoidRule | |
| #include<iostream> | |
| #include<cmath> | |
| #define f(x)(sin(x)) | |
| using namespace std; | |
| int main() | |
| { | |
| float a,b,sum,n,h; | |
| int i; | |
| cout<<"Enter Initial Limit of x (a):"; | |
| cin>>a; | |
| cout<<"Enter Final Limit of x (b):"; | |
| cin>>b; | |
| cout<<"Enter Number Of Intervals n:"; | |
| cin>>n; | |
| h=(b-a)/n; | |
| sum=(f(a)+f(b)); | |
| for(i=1;i<n;i++) | |
| { | |
| sum=sum+2*f(a+(i*h)); | |
| } | |
| sum=sum*h/2; | |
| cout<<sum; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment