Last active
October 28, 2017 16:27
-
-
Save jesuscmadrigal/65f2eb1758b25dfe6427e0206b67d292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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