Let’s understand the Simpson’s 3/8th rule method in numerical analysis and implement Simpsons 3/8 Rule in C programming language. You will get an overall idea about Simpson’s rule here.
What is Simpsons 3/8 Rule?
The Simpson’s 3/8th rule was developed by a mathematician named Thomas Simpson. Integration is the process of measuring the area under a function plotted on a graph.
The Simpson’s 3/8th rule is used in complex numerical integrations. This integration method uses parabolas to approximate each part of the curve. It is basically used to measure an area in a curve.
The Simpson’s 3/8th method is used for uniformly sampled function integration purpose. The Simpson’s 3/8th integration method is primarily used for numerical approximation of definite integrals.
Simpson’s Rule Formula

Algorithm For Simpson’s 3/8 Rule
1 2 3 4 5 6 7 8 | Step 1. Input a, b and the number of intervals. Step 2. Compute the value of h using this formula: h = (b - a) / n Step 3. Calculate the value of sum using this formula: sum = f(a) + f(b) Step 4. If n is an odd number, then sum = sum + 2 * y(a + i * h) Else sum = sum + 3 * y(a + i * h) Step 5. Calculate the Simpson's integration value using this formula: sum* 3 * h / 8 |
Note: This C Program for Simpson’s 3/8 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 3/8th 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 | #include<stdio.h> float function(float temp) { return 1 / (1 + temp * temp); } int main() { float lower_bound, upper_bound, h, sum = 0, value; int count, interval; printf("Enter Lower Boundary Value:\t"); scanf("%f", &lower_bound); printf("Enter Upper Boundary Value:\t"); scanf("%f", &upper_bound); printf("\nEnter Interval Limit:\t"); scanf("%d", &interval); h = (upper_bound - lower_bound) / interval; sum = function(lower_bound) + function(upper_bound); for(count = 1; count < interval; count++) { if(count % 3 == 0) { sum = sum + 2 * function(lower_bound + count * h); } else { sum = sum + 3 * function(lower_bound + count * h); } } value = (3 * h / 8) * sum; printf("\nValue of Simpson's 3/8 Rule Integration:\t%f\n", value); return 0; } |
Output

Note: This C Program for Simpsons Integration 3/8 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 3/8 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 37 38 39 40 41 42 | #include #include int main() { float x[10], y[10], sum = 0, h; int count, limit, m, n; printf("\nEnter Limit:\t"); scanf("%d", &limit); for(count = 0; count < limit; count++) { printf("\nEnter Value For X[%d]:\t", count); scanf("%f", &x[count]); printf("\nEnter Value For F{x[%d]}:\t", count); scanf("%f", &y[count]); } h = x[1] - x[0]; limit = limit - 1; sum = sum + y[0]; for(count = 1; count < limit; count++) { if(m == 0 || n == 0) { sum = sum + 3 * y[count]; if(m == 1) { n = 1; } m = 1; } else { sum = sum + 2 * y[count]; m = 0; n = 0; } } sum = sum + y[count]; sum = sum * (3 * h / 8); printf("\n\nSimple 3/8 Rule Integral Value:\t%f\n", sum); return 0; } |
Output

If you have any doubts about the implementation of Simpson’s 3/8th method in C programming, let us know about it in the comment section. Find more about it on Wikipedia.