aboutsummaryrefslogtreecommitdiff
path: root/c05/ex00/ft_iterative_factorial.c
diff options
context:
space:
mode:
Diffstat (limited to 'c05/ex00/ft_iterative_factorial.c')
-rw-r--r--c05/ex00/ft_iterative_factorial.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/c05/ex00/ft_iterative_factorial.c b/c05/ex00/ft_iterative_factorial.c
new file mode 100644
index 0000000..fa64f59
--- /dev/null
+++ b/c05/ex00/ft_iterative_factorial.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_iterative_factorial.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/06 16:48:21 by cacharle #+# #+# */
+/* Updated: 2019/07/06 17:14:26 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+int ft_iterative_factorial(int nb)
+{
+ int acc;
+ int i;
+
+ if (nb < 0)
+ return (0);
+ if (nb == 0)
+ return (1);
+ acc = 1;
+ while (nb > 0)
+ acc *= nb--;
+ return (acc);
+}