piscine/c05/ex02/ft_iterative_power.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

55 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/13 11:12:36 by whaffman #+# #+# */
/* Updated: 2024/06/14 12:18:06 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
int ft_iterative_power(int nb, int power)
{
int result;
result = 1;
if (power < 0)
return (0);
if (power == 0)
return (1);
while (power > 0)
{
result *= nb;
power--;
}
return (result);
}
#ifdef DEBUG
int main(void)
{
int i;
int j;
i = -3;
j = -3;
while (i < 5)
{
while (j < 5)
{
printf("%d^%d = %d\n", i, j, ft_iterative_power(i, j));
j++;
}
j = -3;
i++;
}
return (0);
}
#endif