mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 13:17:16 +01:00
Piscine42
This commit is contained in:
35
C05/ex05/ft_sqrt.c
Executable file
35
C05/ex05/ft_sqrt.c
Executable file
@@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user