piscine/c05/ex05/ft_sqrt.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

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