Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / power.cpp
diff options
context:
space:
mode:
Commit18c1c983a2ad2d514afe1211ca6de65132e861a6 (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2022-01-05 18:18:41 +0200
Committer
 GitHub <noreply@github.com>
2022-01-05 18:18:41 +0200
Files79313161502057dce430f3b7486aeb9279bb207d /Sem. 12/power.cpp
Introduction_to_programming_FMI-18c1c983a2ad2d514afe1211ca6de65132e861a6.tar
Introduction_to_programming_FMI-18c1c983a2ad2d514afe1211ca6de65132e861a6.tar.gz
Introduction_to_programming_FMI-18c1c983a2ad2d514afe1211ca6de65132e861a6.zip
Parentbd775b43bdf729aa151fe851d1bed9aef52622a1 (diff)
Create power.cpp
1 files changed, 26 insertions, 0 deletions
-rw-r--r--Sem. 12/power.cpp26
diff --git a/Sem. 12/power.cpp b/Sem. 12/power.cpp
new file mode 100644
index 0000000..b089e6c
--- /dev/null
+++ b/Sem. 12/power.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+
+
+
+unsigned power(unsigned n, unsigned k) //Log(k)
+{
+ if (k == 0)
+ return 1;
+
+ if (k % 2 == 1)
+ return n * power(n, k - 1);
+ else
+ {
+ unsigned temp = power(n, k / 2);
+ return temp * temp;
+ }
+}
+// n - в двоична бройна система ми трябват log(n) символа за да го запиша
+// k = 10000000000 - Правите Log(k) стъпки
+// k = 11111111111 - правите 2*log(K) стъпки
+
+
+int main()
+{
+ std::cout << power(2, 8) << std::endl;
+}