Let us understand what is Euler’s method in numerical analysis and learn how to implement algorithm of Euler’s method in C programming with its explanation, output, advantages, disadvantages and much more.

#### What is Euler’s method?

The Euler’s method is a first-order numerical method and is used to solve differential equations. It is also popularly known as **Forward Euler’s method**.

This is a very basic method for numerical integration of ordinary differential equations.

The Euler’s numerical analysis method is very simple to implement but it does not provide accurate results under some circumstances.

Therefore, mathematicians developed a modified version of Euler’s method which is known as **Euler’s modified method**.

#### Euler’s Formula

The solution for Euler’s numerical method is generated by iterating on the two formulas:

x_{n + 1} = x_{n} + h

y_{n + 1} = y_{n} + h*f(x_{n}, y_{n})

where h = length of subdivisions

#### Advantages

- It can be used for simple non-linear initial value problems.
- The Euler’s numerical method is direct in nature and simple to implement.

#### Disadvantages

- The Euler’s method is not so accurate and unstable.
- The approximation error is also not stable.
- If the value for h is large, then it does not give proper results.

**Note:** This code for Euler’s method in C programming is compiled with GNU GCC compiler on CodeLite IDE. However, these codes are compatible with all other operating systems.

#### Method 1: C Program for Euler’s Method using For Loop

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 | #include<stdio.h> float euler_function(float a, float b) { float result; result = a * b; return (result); } int main() { float y1, y2, x1, interval_start, interval_end, length; int count; printf("\nEnter value for Interval start:\t"); scanf("%f", &interval_start); printf("\nEnter value for Interval end:\t"); scanf("%f", &interval_end); printf("\nEnter value for width:\t"); scanf("%f", &length); printf("\nEnter value for Y(1):\t"); scanf("%f", &y1); printf("\n\nX\tCorresponding Y value\n"); for(x1 = interval_start, count = 2; x1 <= interval_end + length; x1 = x1 + length, count++) { y2 = y1 + length * euler_function(x1, y1); printf("\n%.4f\t%.4f ", x1, y2); y1 = y2; } return 0; } |

#### Method 2: Euler’s method in C programming using While Loop

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 euler_function(float t1, float t2); int main() { float start_value, end_value, t1, t2, width, temp, z; printf("\nEnter value for Interval start:\t"); scanf("%f", &start_value); printf("\nEnter value for Interval end:\t"); scanf("%f", &end_value); printf("\nEnter value for width:\t"); scanf("%f", &width); printf("\nEnter value for error:\t"); scanf("%f", &temp); t1 = start_value; t2 = end_value; printf("\nX\tCorresponding Y values\n"); while(t1 <= temp) { z = width * euler_function(t1, t2); t2 = t2 + z; t1 = t1 + width; printf("%0.4f\t%0.4f\n", t1, t2); } return 0; } float euler_function(float t1, float t2) { float temp; temp = t1 + t2; return temp; } |

#### Output

If you have any doubts about the implementation of Euler’s method in C programming, let us know about it in the comment section. Find more about it on **Wikipedia**.