Skip to content

Instantly share code, notes, and snippets.

@jesuscmadrigal
Last active October 28, 2017 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesuscmadrigal/65f2eb1758b25dfe6427e0206b67d292 to your computer and use it in GitHub Desktop.
Save jesuscmadrigal/65f2eb1758b25dfe6427e0206b67d292 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
double sqrt(double);
int main()
{
int x;
cout<< "Give a number"<< endl;
cin>> x;
double result = sqrt(x);
cout<< "Final result is "<< result<< endl;
return 0;
}
double sqrt(double number)
{
double error=0.000001;
double s= number;
while ((s- number/s)>error)
{
s = (s+number/s)/2;
cout << " Intermediate results= " <<s<< endl;
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment