-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_sqrt.c
38 lines (34 loc) · 1.17 KB
/
ft_sqrt.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dalves-p <dalves-p@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/15 19:02:03 by dalves-p #+# #+# */
/* Updated: 2021/06/29 18:47:52 by dalves-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** LIBRARY: <math.h>
** DESCRIPTION:
** The ft_sqrt() function compute the non-negative square root of nb.
*/
int ft_sqrt(int nb)
{
int imp;
int c;
imp = 1;
c = 0;
while (nb > 0)
{
nb = nb - imp;
imp = imp + 2;
c++;
}
if (nb == 0)
return (c++);
else
return (0);
}