first commit
This commit is contained in:
30
C05/ex00/ft_iterative_factorial.c
Normal file
30
C05/ex00/ft_iterative_factorial.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_iterative_factorial.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/23 20:19:51 by adjoly #+# #+# */
|
||||
/* Updated: 2023/07/31 14:43:40 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_iterative_factorial(int nb)
|
||||
{
|
||||
int i;
|
||||
int result;
|
||||
|
||||
i = 1;
|
||||
result = 1;
|
||||
if (nb < 0)
|
||||
return (0);
|
||||
if (nb == 0 || nb == 1)
|
||||
return (1);
|
||||
while (i <= nb)
|
||||
{
|
||||
result *= i;
|
||||
i++;
|
||||
}
|
||||
return (result);
|
||||
}
|
Reference in New Issue
Block a user