C C++ CODE : Trapezoidal rule for integration

Working C C++  Source code program for Trapezoidal rule for integration
/************* TRAPEZOID FULE FOR INTEGRATION *****************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
    char choice='y';
    float f,x,h,a,b,sum;
    clrscr();
    cout<<"a & b ? ";cin>>a>>b;
    do{
        sum=0;
        x=a;
        cout<<"Enter value of h ? ";cin>>h;
        while(x<b)
        {
            sum+=(funct(x)+funct(x+h));
            x=x+h;
        }
        cout<<endl<<"The integration is: "<<sum*h/2<<endl;
        cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
    } while(choice=='y');
    getch();
    return 0;
}

float funct(float x)
{
    return x*exp(x)-2;   // sin takes arguments in radian........
}

1 comment :

  1. Can someone help me with C++ code in numerical integration using trapezoidal method to integrate e^-x^2/2

    ReplyDelete

Your Comment and Question will help to make this blog better...