**Source Code:**

///integration of given function using Simpson's 1/3 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)+4*y(x0+h);for(i = 3; i<=n-1; i+=2){s += 4*y(x0+i*h) + 2*y(x0+(i-1)*h);}printf("Value of integral is %6.4f\n",(h/3)*s);return 0;}

this program is not correct -- for a correct solution use this link -- http://www.codewithc.com/c-program-for-simpson-1-3-rule/

ReplyDeletethis is correct program

DeleteInstead of return 1/1+(x*x),it should be written as return f because every function is different for different problems

ReplyDeleteCan you please tell me why we have to use i=3 in the for loop in initilization part with increment i=i+2.

ReplyDelete