diff options
author | Haidong Ji | 2022-04-15 15:51:30 -0500 |
---|---|---|
committer | Haidong Ji | 2022-04-15 15:51:30 -0500 |
commit | 442a49ad5a48d417345959b903ae6a6d32d55759 (patch) | |
tree | c7127bb497e5e439018b1915e0136eec2c9cb124 /23_power_rec |
Excellent fundamentals and displine training, many tools and techniques
exercises: gdb, emacs, valgrind, git
Diffstat (limited to '23_power_rec')
-rw-r--r-- | 23_power_rec/.gitignore | 2 | ||||
-rw-r--r-- | 23_power_rec/README | 19 | ||||
-rw-r--r-- | 23_power_rec/grade.txt | 45 | ||||
-rw-r--r-- | 23_power_rec/power.c | 12 | ||||
-rw-r--r-- | 23_power_rec/power.o | bin | 0 -> 1512 bytes | |||
-rwxr-xr-x | 23_power_rec/test-power | bin | 0 -> 49296 bytes | |||
l--------- | 23_power_rec/test-power.c | 1 |
7 files changed, 79 insertions, 0 deletions
diff --git a/23_power_rec/.gitignore b/23_power_rec/.gitignore new file mode 100644 index 0000000..d343b3c --- /dev/null +++ b/23_power_rec/.gitignore @@ -0,0 +1,2 @@ +power +Makefile diff --git a/23_power_rec/README b/23_power_rec/README new file mode 100644 index 0000000..3eb89f0 --- /dev/null +++ b/23_power_rec/README @@ -0,0 +1,19 @@ +Write a recursive function unsigned power(unsigned x, unsigned y) which computes x +to the y power. Note the function signature (unsigned ints). +Note that while 0 to the 0 is undefined in mathematics, +we specify that 0 to the 0 shall be 1 for this function. + +Save it into a file called power.c + +You MUST use recursion (no iteration). + + +Use your test-power.c from your previous assignment to test your implementation +of power. You can symlink the file from the previous assignment into this directory: + +ln -s ../22_tests_power/test-power.c ./ + +You should then write a Makefile which will compile each C file separately +to an object file, and like them together. + + diff --git a/23_power_rec/grade.txt b/23_power_rec/grade.txt new file mode 100644 index 0000000..6ee2635 --- /dev/null +++ b/23_power_rec/grade.txt @@ -0,0 +1,45 @@ +Grading at Sat 30 Oct 2021 02:41:44 AM UTC +Attempting to compile power.c +Attempting to compile power.o with our main +Checking for unsigned power (unsigned x, unsigned y) +Found on line 4, column 1 +Checking for no iteration (do, while, for) +Checking that power is recursive +0^0 was Correct +0^1 was Correct +0^2 was Correct +0^6 was Correct +0^8 was Correct +0^11 was Correct +1^0 was Correct +1^1 was Correct +1^2 was Correct +1^6 was Correct +1^8 was Correct +1^11 was Correct +4^0 was Correct +4^1 was Correct +4^2 was Correct +4^6 was Correct +4^8 was Correct +4^11 was Correct +5^0 was Correct +5^1 was Correct +5^2 was Correct +5^6 was Correct +5^8 was Correct +5^11 was Correct +9^0 was Correct +9^1 was Correct +9^2 was Correct +9^6 was Correct +9^8 was Correct +9^11 was Correct +12^0 was Correct +12^1 was Correct +12^2 was Correct +12^6 was Correct +12^8 was Correct +12^11 was Correct + +Overall Grade: A diff --git a/23_power_rec/power.c b/23_power_rec/power.c new file mode 100644 index 0000000..6be0c74 --- /dev/null +++ b/23_power_rec/power.c @@ -0,0 +1,12 @@ +#include <stdio.h> +#include <stdlib.h> + +unsigned power(unsigned x, unsigned y) { + if (y == 0) { + return 1; + } + if (y == 1) { + return x; + } + return x * power(x, y-1); +} diff --git a/23_power_rec/power.o b/23_power_rec/power.o Binary files differnew file mode 100644 index 0000000..58b2c78 --- /dev/null +++ b/23_power_rec/power.o diff --git a/23_power_rec/test-power b/23_power_rec/test-power Binary files differnew file mode 100755 index 0000000..8c63568 --- /dev/null +++ b/23_power_rec/test-power diff --git a/23_power_rec/test-power.c b/23_power_rec/test-power.c new file mode 120000 index 0000000..7480020 --- /dev/null +++ b/23_power_rec/test-power.c @@ -0,0 +1 @@ +../22_tests_power/test-power.c
\ No newline at end of file |