#include<iostream>
using namespace std;
int main()
{
int i,n;
float x[10],y[10],h,sum;
cout<<"Enter no of values in table: ";
cin>>n;
cout<<"Enter X & corresponding Y:\n";
for(i=0;i<n;i++)
cin>>x[i]>>y[i];
h=x[1]-x[0];
sum=y[0]+y[n-1];
for(i=1;i<n-1;i++)
{
if(i%3==0)
sum+=2*y[i];
else
sum+=3*y[i];
}
cout<<"Integral vlaue="<<(3*(h/8))*sum;
return 0;
}
using namespace std;
int main()
{
int i,n;
float x[10],y[10],h,sum;
cout<<"Enter no of values in table: ";
cin>>n;
cout<<"Enter X & corresponding Y:\n";
for(i=0;i<n;i++)
cin>>x[i]>>y[i];
h=x[1]-x[0];
sum=y[0]+y[n-1];
for(i=1;i<n-1;i++)
{
if(i%3==0)
sum+=2*y[i];
else
sum+=3*y[i];
}
cout<<"Integral vlaue="<<(3*(h/8))*sum;
return 0;
}
No comments:
Post a Comment