piscine/c05/ex00/ft_iterative_factorial.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

45 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/13 10:52:17 by whaffman #+# #+# */
/* Updated: 2024/06/13 11:06:44 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
int ft_iterative_factorial(int nb)
{
int result;
result = 1;
if (nb >= 0)
{
while (nb > 1)
result *= nb--;
return (result);
}
return (0);
}
#ifdef DEBUG
int main(void)
{
int i;
i = -3;
while (i < 10)
{
printf("%d! = %d\n", i, ft_iterative_factorial(i));
i++;
}
return (0);
}
#endif