47 lines
1.2 KiB
C
47 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_sqrt.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/06/13 12:07:01 by whaffman #+# #+# */
|
|
/* Updated: 2024/06/13 12:18:19 by whaffman ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdio.h>
|
|
|
|
int ft_sqrt(int nb)
|
|
{
|
|
int i;
|
|
|
|
if (nb <= 0)
|
|
return (0);
|
|
i = 1;
|
|
while (i * i <= nb)
|
|
{
|
|
if (i * i == nb)
|
|
return (i);
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
int main(void)
|
|
{
|
|
int i;
|
|
|
|
i = -3;
|
|
while (i < 10)
|
|
{
|
|
printf("sqrt(%d) = %d\n", i, ft_sqrt(i));
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|
|
|
|
#endif
|