Search:

Submit Article

# SIMPSON'S 1/3 RULE

Posted By: Binghamton Fischer     Category: C Programming     Views: 94134

## Code for SIMPSON'S 1/3 RULE in C Programming

```#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10],sum=0,h,temp;
int i,n,j,k=0;
float fact(int);
clrscr();
printf("\nhow many record you will be enter: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n\nenter the value of x%d: ",i);
scanf("%f",&x[i]);
printf("\n\nenter the value of f(x%d): ",i);
scanf("%f",&y[i]);
}
h=x[1]-x[0];
n=n-1;
sum = sum + y[0];
for(i=1;i<n;i++)
{
if(k==0)
{
sum = sum + 4 * y[i];
k=1;
}
else
{
sum = sum + 2 * y[i];
k=0;
}
}
sum = sum + y[i];
sum = sum * (h/3);
printf("\n\n  I = %f  ",sum);
getch();
}

/*______________________________________         OUT PUT______________________________________how many record you will be enter: 5enter the value of x0: 0enter the value of f(x0): 1enter the value of x1: 0.25enter the value of f(x1): 0.8enter the value of x2: 0.5enter the value of f(x2): 0.6667enter the value of x3: 0.75enter the value of f(x3): 0.5714enter the value of x4: 1enter the value of f(x4): 0.5       I = 0.693250*/```
Share:

Didn't find what you were looking for? Find more on SIMPSON'S 1/3 RULE Or get search suggestion and latest updates.

 Binghamton Fischer author of SIMPSON'S 1/3 RULE is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!