/* Integration of a function by Trapezoidal rule */
#include<stdio.h>
#include<math.h>
/*define your function here*/
float y(float x)
{
return x/1+x;
}
int main()
{
float a, b, h, s;
int i, n;
printf("Enter a, b and no. of subintervals:\n");
scanf("%f%f%d", &a, &b, &n);
h=(b-a)/n;
s=y(a) + y(b);
for(i=0;i<n;i++)
{
s=2*y(a+i*h);
}
printf("Value of integral is %f",(h/2)*s);
return(0);
}
#include<stdio.h>
#include<math.h>
/*define your function here*/
float y(float x)
{
return x/1+x;
}
int main()
{
float a, b, h, s;
int i, n;
printf("Enter a, b and no. of subintervals:\n");
scanf("%f%f%d", &a, &b, &n);
h=(b-a)/n;
s=y(a) + y(b);
for(i=0;i<n;i++)
{
s=2*y(a+i*h);
}
printf("Value of integral is %f",(h/2)*s);
return(0);
}
Comments
Post a Comment