Let’s understand the Simpson’s 1/3rd rule method in numerical analysis and implement Simpsons 1/3 rule in C programming language.
What is Simpsons 1/3 Rule?
The Simpson’s 1/3rd rule is used in numerical integration. Integration is the process of measuring the area under a function plotted on a graph. The Simpson’s 1/3rd rule was developed by a mathematician named Thomas Simpson.
The Simpson’s 1/3rd integration method is primarily used for numerical approximation of definite integrals. This specifically means that Simpson’s integration rule is used in complex integration calculations.
It is a method to approximately calculate the definite integral. The Simpson’s theorem is used to find the area under a given curve. The Simpson’s method corresponds to the 3-point Newton-Cotes quadrature rule as well.
The Simpson’s integration method is a little time consuming compared to other methods in numerical analysis and is also a little difficult to implement computationally.
Simpson’s Rule Formula

Algorithm For Simpson’s 1/3 Rule
1 2 3 4 5 6 | Step 1: Input Values For Lower Boundary, Upper Boundary and Width Step 2: Calculate value for the formula: value = (upper_boundary - lower_boundary) / width Step 3: Compute Width with this formula: width = (upper_boundary - lower_boundary) / value Step 4: Consider y = f(x). Calculate the values of Y(Lower Bound to Upper Bound) for the corresponding X(Lower Bound to Upper Bound) Step 5: Substitute the above values in the Simpsons 1/3 Rule Formula |
Note: This C Program for Simpson’s 1/3 rule is compiled with GNU GCC compiler on CodeLite IDE. However, it is compatible with all other operating systems.
Method 1: C Program For Simpson’s 1/3rd Rule using Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #include<stdio.h> float function(float temp); int main() { int count = 0, value; float x[30], y[30], lower_boundary, upper_boundary, width, m = 0, n = 0, result; printf("\nEnter value for Lower Boundary:\t"); scanf("%f", &lower_boundary); printf("\nEnter value for Upper Boundary:\t"); scanf("%f", &upper_boundary); printf("\nEnter value for Width:\t"); scanf("%f", &width); value = (upper_boundary - lower_boundary) / width; if(value % 2 == 1) { value = value + 1; } width = (upper_boundary - lower_boundary) / value; printf("\nModified Values:\n"); printf("\nMid Point:\t%d\n", value); printf("\nWidth:\t%f\n", width); printf("\nY values\n"); while(count <= value) { x[count] = lower_boundary + count * width; y[count] = function(x[count]); printf("\nY[%d] = %f", count, y[count]); count++; } count = 1; while(count < value) { if(count % 2 == 1) { m = m + y[count]; } else { n = n + y[count]; } count++; } result = width / 3 * (y[0] + y[value] + 4 * m + 2 * n); printf("\n\nSimpson's Rule Integration:\t%f\n", result); return 0; } float function(float temp) { return(1 / (1 + temp)); } |
Output

Note: This C Program for Simpsons Integration 1/3 rule is compiled with GNU GCC compiler on Linux Ubuntu operating system. However, it is compatible with all other operating systems.
Method 2: C Program For Simpsons 1/3 Rule without using Function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include<stdio.h> #include<math.h> int main() { int interval, count; float m = 0, n = 0, sum, lower_limit, upper_limit, length; printf("\nEnter the Intervals:\t"); scanf("%d", &interval); printf("\nEnter Lower Limit:\t"); scanf("%f", &lower_limit); printf("\nEnter Upper Limit:\t"); scanf("%f", &upper_limit); length = (upper_limit - lower_limit) / interval; if(interval%2 == 0) { for(count = 1; count <= interval - 1; count++) { if(count%2 == 0) { m = m + (lower_limit + count * length); } else { n = n + (lower_limit + count * length); } } sum = length / 3 * (lower_limit + upper_limit + 4 * n + 2 * m); printf("\nSimpson's Rule Value:\t%f\n", sum); } else { printf("\nThe values are Invalid\n"); } return 0; } |
Output

If you have any doubts about the implementation of Simpson’s 1/3rd method in C programming, let us know about it in the comment section. Find more about it on Wikipedia.
Why to waste time by writing a C Program for Simpson’s Rule? Who sees such kinds of C Programs these days?
You may be thinking right. But, once in a bluemoon, someone may search for these kind of C programs. My main motive is to make Internet a resourceful place. I believe if any article is correct and holds some value, it should be there on the internet.
This code is too good. Thanks for such an easy program for Simpson’s Formula in C Programming
Thanks for the integration by simpson 1/3 and 3/8 rule in c programming. This has made my day. 🙂
Why waste time? He’s not. For one thing, if you bothered to THINK, you’d have realized that by just reading the C code, you get the ALGORITHM that you can render in any language you choose. And it also happens that Pascal and C are the basis for a great many modern languages today. Not to mention C is still in use in embedded systems because of its speed and it’s ability in IO and operating system interfacing. A lot of drivers are written in C START THINKING!
How can I solve Simpsons Rule in C Programming For 3/8th Rule? Can I modify this program?
Amazing code. Thanks
Pingback: Implement Bisection Method in C Programming - CodingAlpha
To what function in is this being applied to? I only see see the Simpson rule
How to calculate the integral using the Weddles’s rule ?
Please check our recent program or search “Weddle” in the CodingAlpha search bar.
very nice and easily understandable code
How to plot corresponding area of the integral in Simpson 1/3 rule with c program?
Your thoughts are correct