mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2025-12-16 05:58:07 +01:00
36 lines
1.1 KiB
C
Executable File
36 lines
1.1 KiB
C
Executable File
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_sqrt.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/12/12 16:05:20 by fgras-ca #+# #+# */
|
|
/* Updated: 2022/12/14 15:58:40 by fgras-ca ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
int ft_sqrt(int nb)
|
|
{
|
|
int i;
|
|
|
|
if (nb < 0)
|
|
{
|
|
return (0);
|
|
}
|
|
if (nb == 1)
|
|
{
|
|
return (1);
|
|
}
|
|
i = 1;
|
|
while (i < nb / i && i < 46341)
|
|
{
|
|
i++;
|
|
}
|
|
if (i * i == nb)
|
|
{
|
|
return (i);
|
|
}
|
|
return (0);
|
|
}
|