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

51 lines
1.3 KiB
C

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