C C++ CODE : Simpsons 1/3 rule for integration

Working C C++  Source code program for Simpsons 1/3 rule for integration
/************** SIPMPSONS 1/3 RULE ***********************/

#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)+4*funct(x+h)+funct(x+2*h));
            x=x+2*h;
        }
        cout<<endl<<"The integration is: "<<sum*h/3<<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........
}

No comments :

Post a Comment

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