31 lines
1.1 KiB
C
31 lines
1.1 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_is_prime.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2022/07/20 13:40:46 by cchauvet #+# #+# */
|
||
|
/* Updated: 2022/07/25 17:38:33 by cchauvet ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
int ft_is_prime(int nb)
|
||
|
{
|
||
|
int i;
|
||
|
long int nbr_out;
|
||
|
|
||
|
if (nb < 0)
|
||
|
nbr_out = (long int) -nb;
|
||
|
else
|
||
|
nbr_out = (long int) nb;
|
||
|
i = 2;
|
||
|
while (i <= nbr_out / i)
|
||
|
{
|
||
|
if (nbr_out % i == 0)
|
||
|
return (0);
|
||
|
i++;
|
||
|
}
|
||
|
return (1);
|
||
|
}
|