Trapezoidal Rule using C programming :


In mathematics, the trapezoid rule is a numerical integration method, that is, a method to calculate approximately the value of the definite integral.
The Formula is :
                    
=

or 
h/2[(X)+2*R];
Where X =y0+y1
           R= y1+y2+y3+........................yn-1

Trapezoidal Rule using C programming :

#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,sum;
    sum=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++)
    {
       sum=sum+(2*y[i]);
    }
    printf("The Output is %f",h/2*((y[0]+y[n-1])+sum));
    return 0;
}

Comments

Popular posts from this blog

Newton Backward Interpolation Formula