Thursday, January 30, 2014

trapezoidal method

#include<iostream.h>
float y(float x)
{
    return(x/(1+x));
}

void main()
{
    float a,b,h,I;
    int i,n;
    cout<<"\nEnter values of a,b and number of interal=";
    cin>>a>>b>>n;
    h=(b-a)/n;
    I=y(a)+y(b);
    for(i=1;i<=n-1;i++)
    {
        I+=2*y(a+i*h);
    }
   cout<<"\nThe Integration is="<<h*I/2;
}

No comments:

Post a Comment