42_C_PISCINE/C/c05v4/ex02/ft_iterative_power.c

26 lines
1.1 KiB
C
Raw Normal View History

2023-05-17 12:45:25 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:17:04 by cchauvet #+# #+# */
/* Updated: 2022/07/26 16:55:22 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int nbr_out;
if (power < 0)
return (0);
if (power == 0)
return (1);
nbr_out = nb;
while (--power > 0)
nbr_out = nbr_out * nb;
return (nbr_out);
}