by Dinesh Thakur Category: Control Structures

The desired accuracy is upto 6 decimal places. The formula for finding a real root of an equation f(x) = 0 is given by

                           Xn+1= Xn- f(xn)/f '(xn) n = 0, 1, 2...


X0 denotes the initial approximate value of the root. This value is modified at each iteration. The absolute value of the difference between the new and the old value of the root is computed at the end of each iteration. When the difference reaches an acceptable level of accuracy, control goes out of the loop.


#include <iostream.h>

#include <math.h>
void main()
      float x0,xl,x,error=2;
      int i;
      cout<<"Enter the initial value of root \n";
      cout<<"error "<<error;
      while (error>0.1e-5)
                xl =x0-(x0*x0+2*x0+1)/(2*x0+2);
                error = fabs (xl-x0);
                cout<<"Error "<<error;
                cout<<"The real root is "<<x0;

finds the real root of an equation using Newton Raphson technique

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles