0% found this document useful (0 votes)
24 views

Simpson 3/8 Using Function

This C program uses Simpson's 3/8 Rule to numerically calculate the definite integral of a function between two bounds. The program prompts the user to input the number of intervals and the bounds, calculates the interval width h, sums the function values using Simpson's rule, and prints the final integral value I.

Uploaded by

apk1995apk
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Simpson 3/8 Using Function

This C program uses Simpson's 3/8 Rule to numerically calculate the definite integral of a function between two bounds. The program prompts the user to input the number of intervals and the bounds, calculates the interval width h, sums the function values using Simpson's rule, and prints the final integral value I.

Uploaded by

apk1995apk
Copyright
© © All Rights Reserved
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 3/8 Rule Using Function


#include<stdio.h>
#include<conio.h>
#include<math.h>
float f (float x)
{
float z;
z=x*x-5*x+6;
return z;
}
void main()
{
int i,n;
float h,a,b,sum=0,sum1=0,sum2=0,I;
clrscr();
printf("\nEnter no. of values: \n");
scanf("%d",&n);
printf("\nEnter the values of a and b: \n");
{
scanf("%f%f", &a,&b);
}
h=(b-a)/n;
printf("\n The h= %f",h);
sum+=f(a)+f(b);
// printf("\n Sum = %f \n ", sum);
for(i=1;i<n;i++)
{
if(i%3==0)
{
sum2+=f(a+i*h);
// printf("\n Sum 2 = %f \n",sum2);
}
else
{
sum1+=f(a+i*h);
// printf("Sum 1 = %f \n",sum1);
}
}
I=((3*h/8)*(sum+3*(sum1)+2*(sum2)));
printf("\n The value of I= %f ",I);
getch();
}







Output :
Enter no. of values:
6
Enter the values of a and b:
1.5
6
The h= 0.750000
The value of I= 13.500000

You might also like