aboutsummaryrefslogtreecommitdiff
path: root/c05/ex03
diff options
context:
space:
mode:
Diffstat (limited to 'c05/ex03')
-rw-r--r--c05/ex03/ft_recursive_power.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/c05/ex03/ft_recursive_power.c b/c05/ex03/ft_recursive_power.c
new file mode 100644
index 0000000..94c4fbd
--- /dev/null
+++ b/c05/ex03/ft_recursive_power.c
@@ -0,0 +1,22 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_recursive_power.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/06 17:39:43 by cacharle #+# #+# */
+/* Updated: 2019/07/06 19:32:17 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int ft_recursive_power(int nb, int power)
+{
+ if (power < 0)
+ return (0);
+ if (power == 0)
+ return (1);
+ if (power == 1)
+ return (nb);
+ return nb * ft_recursive_power(nb, power - 1);
+}