31 lines
1.1 KiB
C
31 lines
1.1 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_iterative_power.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2023/07/23 22:29:27 by adjoly #+# #+# */
|
||
|
/* Updated: 2023/07/25 19:40:26 by adjoly ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
int ft_iterative_power(int nb, int power)
|
||
|
{
|
||
|
int result;
|
||
|
|
||
|
if (power < 0)
|
||
|
return (0);
|
||
|
if (power == 0)
|
||
|
return (1);
|
||
|
if (power == 1)
|
||
|
return (nb);
|
||
|
result = nb;
|
||
|
while (power > 1)
|
||
|
{
|
||
|
result *= nb;
|
||
|
power--;
|
||
|
}
|
||
|
return (result);
|
||
|
}
|