Created
February 2, 2020 16:11
-
-
Save MShirazAhmad/6db60af95b659c0188a233c8b3b96742 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
| //Simpson's1/3rule | |
| #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++) | |
| { | |
| if(i%2==0) | |
| sum=sum+2*f(a+(i*h)); | |
| else | |
| sum=sum+4*f(a+(i*h)); | |
| } | |
| sum=sum*h/3; | |
| cout<<sum; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment