/* WAP of Simpson's 1/3 */
#include<stdio.h> #include<conio.h> void main() { float x[100],y[100],odd, even,fx,h; int size,i; clrscr(); printf("How many value you want to enter: "); scanf("%d",&size); for(i=0; i<size; i++) { printf("Enter elements of x[%d]:\n",i); scanf("%f",&x[i]); printf("Enter elements of y[%d]:\n",i); scanf("%f",&y[i]); } h = x[2]-x[1]; printf("\nh = %f",h); for(i=1; i<size-1; i++) { if(i%2==0) { even += 2*y[i]; } else //if(i%2 != 0) { odd += 4*y[i]; } } fx = ( h/3) * ( y[0] + y[size-1] + odd + even ); printf("\nf(x)= %f",fx); getch(); }