Can anyone explain the mathematical correctness of the following code to find the square root of a positive number in C++ ?
#include <iostream>
#include <cmath>
using namespace std;
int main(){
float a; cin>>a;
cout<<"Answer by Math library\n"<<sqrt(a)<<"\n";
//the following is the code for finding the square root of a positive double
double g=a;
while(abs(g*g-a)>1e-8){
g= (g+(a/g))/2;
}
cout<<"Answer by this algorithm\n"<<g<<"\n";
return 0;
}