42/d04/ex02/ft_iterative_power.c

33 lines
1.1 KiB
C
Raw Normal View History

2016-11-20 02:20:23 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/29 14:35:08 by gtertysh #+# #+# */
/* Updated: 2016/10/29 14:56:28 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int result;
if (power < 0)
{
return (0);
}
else if (power == 0)
{
return (1);
}
result = nb;
while (power > 1)
{
result *= nb;
power--;
}
return (result);
}