0% found this document useful (0 votes)
145 views

Trapezoidal Rule C Program

This C program defines a function f(x) and uses the trapezoidal rule to numerically integrate f(x) between user-input lower and upper bounds divided into n segments. It initializes variables, calculates the area of each trapezoid formed, sums them, and prints the final integration value.

Uploaded by

Mausam Pokhrel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views

Trapezoidal Rule C Program

This C program defines a function f(x) and uses the trapezoidal rule to numerically integrate f(x) between user-input lower and upper bounds divided into n segments. It initializes variables, calculates the area of each trapezoid formed, sums them, and prints the final integration value.

Uploaded by

Mausam Pokhrel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<stdio.

h>
#include<math.h>
#define f(x) 1/(1+pow(x,2))/[tan-1x] limit 0 to 6=
void main()
{
float h,x0,xn,y0,yn,term,val,np;
int i,n;
printf("\n enter the lower and upper limit \n");
scanf("%f %f",&x0,&xn);
printf("\n enter the no of segments=");
scanf("%d",&n);
h=(xn-x0)/n;
y0=f(x0);
yn=f(xn);
term=f(x0)+f(xn);

for(i=1;i<=n-1;i++)
{
np=x0+i*h;
term=term+2*(f(np));
}

val=h/2*term;
printf("\n Value of the integration=%f",val);
}

You might also like