## C Program For Newton Raphson Method

Let us learn how to implement Newton Raphson method in C programming language using functions and for loop.

#### What is Newton-Raphson’s Method?

This method is also popularly known as **Newton’s method**. It is used to find roots of a real-valued function.

The Newton’s method is a better approximation method as compared to some other numerical methods. It is based on the idea of simple linear approximation.

The Newton – Raphson method converges faster than **Bisection method** and **False Position Method**.

This method is named after **Isaac Newton** and **Joseph Raphson** and is used to find a minimum or maximum of a function.

#### Formula

#### Newton-Raphson Algorithm

- Calculate values of derived_function(value) and function(value)
- Calculate m = function(value) / derived_function(value)
- While m is greater than the allowed error

m = function(value) / derivfunction(value)

value = value – m

#### Flowchart For Newton – Raphson Method

**Note:** This C program to find roots of an equation using Newton – Raphson Method has been compiled with CodeLite IDE with GNU GCC compiler in Microsoft Windows 10 operating system.

#### C Program To Implement Newton Raphson Method

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 | #include<stdio.h> #include<stdlib.h> float allowed_error = 0; double function(double value); double derived_function(double value); void newton_raphson_method(double value); int main() { double value; printf("\nEnter a Value:\t"); scanf("%lf", &value); printf("\nEnter Allowed Error:\t"); scanf("%f", &allowed_error); newton_raphson_method(value); return 0; } void newton_raphson_method(double value) { double m = function(value) / derived_function(value); for ( ;abs(m) >= allowed_error; ) { m = function(value) / derived_function(value); value = value - m; } printf("\nRoot Value:\t%f\n", value); } double function(double value) { return (value * value * value - value * value + 2); } double derived_function(double value) { return (3 * value * value - 2 * value); } |

#### Output

In case you get any compilation errors in this C Program for Newton Raphson method or if you have any doubts about it, let us know about it in the comment section below.

For more information on netwon-raphson algorithm, check **Wikipedia**.