Home » C Programs » Newton Raphson Method Program in C

The Newton technique is a higher-order method that results in a more accurate approximation of your function. In most cases, the Newton technique precisely minimises the second order approximation of a function f.

The Newton–Raphson technique is a root-finding algorithm named after Isaac Newton and Joseph Raphson that gives successively improved approximations to the roots of a real-valued function.

In C, data types refer to a comprehensive system for declaring variables or functions of various types. A variable’s type determines how much storage space it takes up and how the bit pattern stored is interpreted.

A data type is a property associated with a piece of data that instructs a computer system on how to interpret its value. Understanding data types ensures that data is collected in the desired format and that each property’s value is as expected.

```
//Newton Raphson Method Program in C
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define f(x) 3*x - cos(x) -1
#define g(x) 3 + sin(x)
void main()
{
float x0, x1, f0, f1, g0, e;
int step = 1, N;
clrscr();
printf("\nEnter initial guess\n");
scanf("%f", &x0);
printf("Enter tolerable error\n");
scanf("%f", &e);
printf("Enter maximum iteration\n");
scanf("%d", &N);
printf("\nStep\t\tx0\t\tf(x0)\t\tx1\t\tf(x1)\n");
do
{
g0 = g(x0);
f0 = f(x0);
if(g0 == 0.0)
{
printf("Mathematical Error");
exit(0);
}
x1 = x0 - f0/g0;
printf("%d\t\t%f\t%f\t%f\t%f\n",step,x0,f0,x1,f1);
x0 = x1;
step = step+1;
if(step > N)
{
printf("Not Convergent");
exit(0);
}
f1 = f(x1);
}
while(fabs(f1)>e);
printf("\nRoot is %f", x1);
getch();
}
```

Enter initial guess

45

Enter tolerable error

4

Enter maximum iteration

2

Step x0 f(x0) x1 f(x1)

1 45.000000 133.474670 10.339390 0.000000

2 10.339390 30.628267 -3.534155 30.628267

Not Convergent