summaryrefslogtreecommitdiff
path: root/I_anno
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-08-19 21:42:40 +0200
committerGitHub <noreply@github.com>2020-08-19 21:42:40 +0200
commit9b48d05c446997a3e953107898f7f0336be470d5 (patch)
treeb41391d600a6ed4be5becc9608a14ed86191ea79 /I_anno
parent9c53748e4ee058d86a02b9478fd161dc58c84e0b (diff)
Update cbrt.cc
alternative way, more easy
Diffstat (limited to 'I_anno')
-rw-r--r--I_anno/Programmazione_2/algorithms/cbrt.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/I_anno/Programmazione_2/algorithms/cbrt.cc b/I_anno/Programmazione_2/algorithms/cbrt.cc
index bbd1ee1..30c7792 100644
--- a/I_anno/Programmazione_2/algorithms/cbrt.cc
+++ b/I_anno/Programmazione_2/algorithms/cbrt.cc
@@ -16,6 +16,19 @@ int cbrt(int n) {
return q;
}
+double cbrt2(int n) {
+ int i = 1;
+ while(i*i*i <= n)
+ ++i;
+ // precision
+
+ --i;
+ while(i*i*i < n)
+ i+=0.000001;
+
+ return i;
+}
+
int main() {
int i;
cin >> i;