29 lines
1.2 KiB
C
29 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_recursive_power.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: sgongas <sgongas@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/02/22 22:59:09 by sgongas #+# #+# */
|
|
/* Updated: 2026/02/22 23:12:08 by sgongas ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
int ft_recursive_power(int nb, int power)
|
|
{
|
|
if (power < 0)
|
|
return (0);
|
|
else if (power == 0 || nb == 0)
|
|
return (1);
|
|
if (power != 1)
|
|
return (nb * ft_recursive_power(nb, power - 1));
|
|
return (nb);
|
|
}
|
|
|
|
// #include <stdio.h>
|
|
// int main(void)
|
|
// {
|
|
// printf("%d\n", ft_recursive_power(5, 2));
|
|
// return (0);
|
|
// }
|