Simpson's 1/3rd program in c for tabulated values
#include<stdio.h> #include<conio.h> #include<math.h> void main() { int i,n; float x[6],y[6],u,k,h=0.05,s,s2,s4,integral; clrscr(); for(i=0;i<7;i++) { printf("enter x[%d]",i); scanf("%f",&x[i]); printf("enter y[%d]",i); scanf("%f",&y[i]); } s=y[0]+y[6]; s2=0; s4=0; for(i=1;i<=5;i=i+2) { s4=s4+y[i]; } for(i=2;i<=4;i=i+2) { s2=s2+y[i]; } integral=(h/3)*(s+2*s2+4*s4); printf("integral is %f",integral); getch(); }
0 comments:
Post a Comment