diff options
Diffstat (limited to '23_power_rec/power.c')
-rw-r--r-- | 23_power_rec/power.c | 12 |
1 files changed, 12 insertions, 0 deletions
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); +} |