aboutsummaryrefslogtreecommitdiff
path: root/c05/ex02/ft_iterative_power.c
diff options
context:
space:
mode:
Diffstat (limited to 'c05/ex02/ft_iterative_power.c')
-rw-r--r--c05/ex02/ft_iterative_power.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/c05/ex02/ft_iterative_power.c b/c05/ex02/ft_iterative_power.c
new file mode 100644
index 0000000..ccfd359
--- /dev/null
+++ b/c05/ex02/ft_iterative_power.c
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_iterative_power.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/06 17:20:15 by cacharle #+# #+# */
+/* Updated: 2019/07/06 17:39:06 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int ft_iterative_power(int nb, int power)
+{
+ int acc;
+
+ if (power < 0)
+ return (0);
+ if (power == 0)
+ return (1);
+ acc = 1;
+ while (power > 0)
+ {
+ acc *= nb;
+ power--;
+ }
+ return (acc);
+}