Skip to content

Instantly share code, notes, and snippets.

@MShirazAhmad
Created February 2, 2020 16:08
Show Gist options
  • Save MShirazAhmad/426950796ce18ad3ac70c74940e34d25 to your computer and use it in GitHub Desktop.
Save MShirazAhmad/426950796ce18ad3ac70c74940e34d25 to your computer and use it in GitHub Desktop.
//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