-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_root.c
34 lines (31 loc) · 1.18 KB
/
ft_root.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_root.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vbrazas <vbrazas@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/24 17:57:05 by vbrazas #+# #+# */
/* Updated: 2017/11/18 17:32:46 by vbrazas ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_root(int n, int rt)
{
int i;
unsigned long int j;
if (n == 1 && rt > 1)
return (1);
if (n <= 3 || rt <= 1)
return (0);
i = 1;
while (++i)
{
j = ft_pow(i, rt);
if (j > (unsigned long int)n)
return (-1);
if (j == (unsigned long int)n)
return (i);
}
return (0);
}