-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_recursive_power.c
80 lines (73 loc) · 1.96 KB
/
ft_recursive_power.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rnarciso <rnarciso@student.42lisboa.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/26 02:46:48 by rnarciso #+# #+# */
/* Updated: 2022/09/27 02:47:57 by rnarciso ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
int ft_recursive_power(int nb, int power)
{
long int nbr;
if (power == 0)
return (1);
if (power < 0)
return (0);
else
{
return (nbr = (nb * ft_recursive_power(nb, (power - 1))));
}
}
/*
void ft_recursive_power_test(int nb, int power)
{
int res;
res = ft_recursive_power(nb, power);
printf(" nb = %d, power = %d, result: %d\n", nb, power, res);
}
int main(void)
{
int nb;
int power;
// testando potencias negativas(deve retornar 0)
printf("[1] Potencias negativas(deve retornar 0)\n");
nb = -4;
while (nb <= 4)
{
power = -4;
while (power < 0)
{
ft_recursive_power_test(nb, power);
power++;
}
nb++;
}
// testando potencias 0(deve retornar 1)
printf("[2] Potencias 0(deve retornar 1)\n");
nb = -4;
power = 0;
while (nb <= 4)
{
ft_recursive_power_test(nb, power);
nb++;
}
// testando potencias 0(deve retornar 1)
printf("[3] Potencias positivas(deve retornar o numero elevado a potencia)\n");
nb = -4;
while (nb <= 4)
{
power = 1;
while (power <= 4)
{
ft_recursive_power_test(nb, power);
power++;
}
nb++;
}
return (0);
}
*/