mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2025-12-16 05:58:07 +01:00
37 lines
1.1 KiB
C
Executable File
37 lines
1.1 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_iterative_power.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/12/12 11:42:46 by fgras-ca #+# #+# */
|
|
/* Updated: 2022/12/12 12:13:42 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
int ft_iterative_power(int nb, int power)
|
|
{
|
|
int resultat;
|
|
int i;
|
|
|
|
i = 0;
|
|
resultat = 1;
|
|
if (power == 0)
|
|
return (1);
|
|
if (nb == 0 && power == 0)
|
|
{
|
|
return (1);
|
|
}
|
|
if (power < 0)
|
|
{
|
|
return (0);
|
|
}
|
|
while (i < power)
|
|
{
|
|
resultat *= nb;
|
|
i++;
|
|
}
|
|
return (resultat);
|
|
}
|