55 lines
1.3 KiB
C
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
|