diff options
author | Santo Cariotti <dcariotti24@gmail.com> | 2020-08-18 11:38:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-18 11:38:38 +0200 |
commit | a105fcc0393b53473b33742f5bf961be9827638e (patch) | |
tree | 7481a99c49fc9df35a2717ba324788aec2c1a999 | |
parent | e06d662de2a01673ce6151ef66d2aa00b271a44c (diff) |
Update sqrt.cc
alternative way to calculate square root
-rw-r--r-- | I_anno/Programmazione_2/algorithms/sqrt.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/I_anno/Programmazione_2/algorithms/sqrt.cc b/I_anno/Programmazione_2/algorithms/sqrt.cc index 01d1079..aa6b032 100644 --- a/I_anno/Programmazione_2/algorithms/sqrt.cc +++ b/I_anno/Programmazione_2/algorithms/sqrt.cc @@ -31,6 +31,14 @@ double sq2(int n) { return sq2_n(n, n/2); } +double sqrt_d(int n) { + double x = 1; + while(abs(x*x-n)>=0.0000001) { + x = ((n/x)+x)/2; + } + return x; +} + int main() { cout << sq(81) << endl; cout << sq2(81) << endl; |