Check out example codes for "Newton's sqrt in c++". It will help you in understanding the concepts better.

Code Example 1

#include<bits/stdc++.h> 
#define EPSILON 0.001 
using namespace std; 

double func(double x) { 
    return x*x*x - x*x + 2; 
} 
  
double derivFunc(double x) { 
    return 3*x*x - 2*x; 
} 
   
void sqrt(double x) { 
    double h = func(x) / derivFunc(x); 
    while (abs(h) >= EPSILON) { 
        h = func(x)/derivFunc(x);    
        x = x - h; 
    } 
    cout << "The value of the root is : " << x; 
} 
  
int main() { 
  	ios::sync_with_stdio(0);
  	cin.tie(0);
    double x0;
  	cin >> x0;
    sqrt(x0); 
    return 0; 
}

Learn ReactJs, React Native from akashmittal.com