Simpson 1/3rd Rule using C programming

The Simpson’s 1/3rd integration method is primarily used for numerical approximation of definite integrals. This specifically means that Simpson’s integration rule is used in complex integration calculations.
It is a method to approximately calculate the definite integral. The Simpson’s theorem is used to find the area under a given curve. The Simpson’s method corresponds to the 3-point Newton-Cotes quadrature rule as well.
The Simpson’s integration method is a little time consuming compared to other methods in numerical analysis and is also a little difficult to implement computationally.

Simpson’s Rule Formula

                 



C Programming For Simpson 1/3rd Rule :



#include<stdio.h>
int main()
{
    int n,i,j;
    printf("Enter the total Number of Input You want");
    scanf("%d",&n);
    float x[n],y[n],h,sume,sumo;
    sume=sumo=0;
    for(i=0;i<n;i++)
    {
        printf("Enter the value of X[%d] : ",i);
        scanf("%f",&x[i]);
    }
    for(i=0;i<n;i++)
    {
        printf("Enter the value of Y[%d] : ",i);
        scanf("%f",&y[i]);
    }
    h=((x[n-1]-x[0])/(n-1));
    for(i=1;i<n-1;i++)
    {
     if(i%2==0)
       {
       sume=sume+(2*y[i]);
       }
     else
       {
       sumo=sumo+(4*y[i]);
       }
    }
    printf("The Output is %f",h/3*((y[0]+y[n-1])+sumo+sume));
    return 0;
}




Comments

Popular posts from this blog

Newton Backward Interpolation Formula