Created
January 21, 2020 00:01
-
-
Save misterpoloy/6efe14b7c8645e6233cdc4338361eee3 to your computer and use it in GitHub Desktop.
Get square root using Newtons formula = The equation πππ€ππ’ππ π =12β(πππππ’ππ π +ππππππ’ππ π )
This file contains hidden or 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 squareroot(double n) { /*return type int which indicates | |
that a decimal is being returned*/ | |
double root = n / 2; | |
for (int i = 0; i < 20; i++) { | |
root = (.5) * (root + (n / root)); | |
} | |
return root; | |
} | |
int main() { | |
cout << squareroot(9) << endl; | |
cout << squareroot(4563) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment