Numerical Methods: Integration of given function using Trapezoidal rule in C
destination source:https://www.programming-techniques.com/?p=210
Source Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ///integration of given function using Trapezoidal rule #include<stdio.h> float y(float x){ return 1/(1+x*x); } int main(){ float x0,xn,h,s; int i,n; printf("Enter x0, xn, no. of subintervals: "); scanf("%f%f%d",&x0,&xn,&n); h = (xn-x0)/n; s = y(x0) + y(xn); for(i = 1; i < n; i++){ s += 2*y(x0+i*h); } printf("Value of integral is %6.4f\n",(h/2)*s); return 0; } |

Related Article
destination source:https://www.programming-techniques.com/?p=210