#include <iostream>
#include <math.h>

double func(double x)
{ return sqrt(5.0/(x+1.0));}


double stephensen(double x0)
{
//Stephensen root finding method
double es,ea;
int maxit=100,iter=0;
es=0.000001;
ea=1.1*es;
double x,x1,x2;
x=0;
while(iter<maxit && ea>es)
{
x1=func(x0);
x2=func(x1);
x=x0-(x1-x0)*(x1-x0)/(x2-2*x1+x0);
ea=fabs(x-x0)*100.0;
x0=x;
iter++;
}
if(iter>=maxit) std::cout <<("Maximum number of iteration is exceeded \n result might not be valid");
return x;
}

int main()
{  double xa,r;
   std::cout << " first guess for the root value : ";
   std::cin >>xa;

   r=stephensen(xa);
   std::cout<<"root value : ="<<r<<"fr="<<func(r)-r;
   return 0;
}
