summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_2/algorithms/sqrt.cc
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-10-18 18:56:43 +0200
committerSanto Cariotti <dcariotti24@gmail.com>2020-10-20 09:08:52 +0200
commitf279107065146a4940f5e73602a1c3c09e58b31d (patch)
treefd892749637a8b6c5c31ccb80bba04ade76ab87a /I_anno/Programmazione_2/algorithms/sqrt.cc
parent4e063e32250312c38d5646840719b62429362b21 (diff)
chore: name of first year folder
Diffstat (limited to 'I_anno/Programmazione_2/algorithms/sqrt.cc')
-rw-r--r--I_anno/Programmazione_2/algorithms/sqrt.cc46
1 files changed, 0 insertions, 46 deletions
diff --git a/I_anno/Programmazione_2/algorithms/sqrt.cc b/I_anno/Programmazione_2/algorithms/sqrt.cc
deleted file mode 100644
index aa6b032..0000000
--- a/I_anno/Programmazione_2/algorithms/sqrt.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-#include<iostream>
-
-using namespace std;
-
-double abs(double n) {
- if(n < 0) return -n;
-
- return n;
-}
-
-
-double sq(int n) {
- double x = n;
- double y = 1;
- while(x-y > 0.0000001) {
- x = (x+y)/2;
- y = n/x;
- }
- return x;
-}
-
-double sq2_n(double n, double a) {
- if(abs(a*a - n) <= 0.000001) {
- return a;
- }
-
- return sq2_n(n, (a+n/a)/2);
-}
-
-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;
- return 0;
-}