mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 13:17:16 +01:00
Piscine42
This commit is contained in:
32
C05/ex00/ft_iterative_factorial.c
Executable file
32
C05/ex00/ft_iterative_factorial.c
Executable file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_iterative_factorial.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/12 09:44:26 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/12 11:00:06 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_iterative_factorial(int nb)
|
||||
{
|
||||
int resultat;
|
||||
|
||||
resultat = 1;
|
||||
if (nb == 0)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
while (nb > 0)
|
||||
{
|
||||
resultat *= nb;
|
||||
nb--;
|
||||
}
|
||||
if (nb < 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
return (resultat);
|
||||
}
|
||||
Reference in New Issue
Block a user