Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / Pract. 09 / task2.cpp
diff options
context:
space:
mode:
Commit97b4d62734acf7533a96b08bcc6044eb94847931 (patch)
Author
 Justsvetoslavov <justsvetoslavov@gmail.com>
2022-01-13 21:15:47 +0200
Committer
 Justsvetoslavov <justsvetoslavov@gmail.com>
2022-01-13 21:15:47 +0200
Files19329717e5479af4bdacf34e3ca5ee8364f0f078 /pract_SI/Pract. 09/task2.cpp
Introduction_to_programming_FMI-97b4d62734acf7533a96b08bcc6044eb94847931.tar
Introduction_to_programming_FMI-97b4d62734acf7533a96b08bcc6044eb94847931.tar.gz
Introduction_to_programming_FMI-97b4d62734acf7533a96b08bcc6044eb94847931.zip
Parent7b3b0c12934abad49aeeea12901627355ab53f9e (diff)
Add Pract. solutions.
1 files changed, 23 insertions, 0 deletions
-rw-r--r--pract_SI/Pract. 09/task2.cpp23
diff --git a/pract_SI/Pract. 09/task2.cpp b/pract_SI/Pract. 09/task2.cpp
new file mode 100644
index 0000000..e52d12d
--- /dev/null
+++ b/pract_SI/Pract. 09/task2.cpp
@@ -0,0 +1,23 @@
+//Way 1
+unsigned Pow(unsigned x, unsigned n)
+{
+ if (n != 0)
+ return x * Pow(x, n - 1);
+
+ return 1;
+}
+
+//Way 2 - more optional
+unsigned power(unsigned x, unsigned n)
+{
+ if (n == 0)
+ return 1;
+
+ if (n % 2 == 1)
+ return x * power(x, n - 1);
+ else
+ {
+ unsigned temp = power(x, n / 2);
+ return temp * temp;
+ }
+} \ No newline at end of file