0% found this document useful (0 votes)
24 views2 pages

STD.: Sybsc (C.S Sub.: Maths Practical: Simpson'S 1/3 Rule

The document contains code to implement Simpson's 1/3 Rule for numerical integration. The code takes user input for the number of data points, the x and y values, calculates the step size h, sums the even and odd terms separately, and computes the integral I as (h/3) * (sum of end points + 4 * sum of odd terms + 2 * sum of even terms). It outputs the calculated value of the integral I.

Uploaded by

apk1995apk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

STD.: Sybsc (C.S Sub.: Maths Practical: Simpson'S 1/3 Rule

The document contains code to implement Simpson's 1/3 Rule for numerical integration. The code takes user input for the number of data points, the x and y values, calculates the step size h, sums the even and odd terms separately, and computes the integral I as (h/3) * (sum of end points + 4 * sum of odd terms + 2 * sum of even terms). It outputs the calculated value of the integral I.

Uploaded by

apk1995apk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Std. : SYBsc (C.

S
Sub. : Maths
Practical : Simpsons 1/3 Rule
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define max 100
void main()
{
int i,n;float x[max],y[max],sum=0,sum1=0,sum2=0,h,I;
clrscr();
printf("\n Enter no of values : \n");
scanf("%d",&n);
printf("\n Enter elements in x : \n");
for(i=0;i<=n;i++)
{
scanf("%f",&x[i]);
}
h=x[1]-x[0];
printf("\n h=%f \n",h);
printf("\n Enter elements in y: \n");
for(i=0;i<=n;i++)
{
scanf("%f",&y[i]);
}
sum+=y[0]+y[n];
for(i=1;i<n;i++)
{
if(i%2==0)
sum2+=y[i];
else
sum1+=y[i];
}
I=(h/3)*(sum+4*(sum1)+2*(sum2));
printf("\n Value of I=%f ",I);
getch();
}

Output :
Enter no of values :
6
Enter elements in x :
3.2
3.3
3.4
3.5
3.6
3.7
3.8
h=0.100000
Enter elements in y:
1.56
2.71
0.999
1.27
2.03
3.14
2.34
Value of I=1.281265

You might also like