From a105fcc0393b53473b33742f5bf961be9827638e Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 18 Aug 2020 11:38:38 +0200 Subject: Update sqrt.cc alternative way to calculate square root --- I_anno/Programmazione_2/algorithms/sqrt.cc | 8 ++++++++ 1 file changed, 8 insertions(+) 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; -- cgit v1.2.3-18-g5258