summaryrefslogtreecommitdiff
path: root/I_anno
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-08-18 11:38:38 +0200
committerGitHub <noreply@github.com>2020-08-18 11:38:38 +0200
commita105fcc0393b53473b33742f5bf961be9827638e (patch)
tree7481a99c49fc9df35a2717ba324788aec2c1a999 /I_anno
parente06d662de2a01673ce6151ef66d2aa00b271a44c (diff)
Update sqrt.cc
alternative way to calculate square root
Diffstat (limited to 'I_anno')
-rw-r--r--I_anno/Programmazione_2/algorithms/sqrt.cc8
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;