calculating the square root of a number
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
double pmid=0,n,st=0,en,mid=0;
double dif=3;
cin>> n; // number whose square root is to be found
en=n; // end number
while(dif>.00000001){
mid =(st+en)/2; //mid number , st = start number
if (mid*mid>n){
en=mid; // re positioning end number
}
else {
st =mid; // re positioning end number
}
dif=fabs(pmid-mid); //difference between previous and present mid values
pmid=mid;
cout <<mid<<" "<<dif<< endl;
}
}
the problem in my results and the results in calculator are different I calculated output of the number 10 as 3.16228 and the google calculator calculates it as 3.16227766017 I think my written code rounds off the value and displays it . How can I get the values as shown by calculator.