33 lines
1.1 KiB
C
33 lines
1.1 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_is_prime.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2016/10/29 20:00:31 by gtertysh #+# #+# */
|
||
|
/* Updated: 2016/10/29 22:06:27 by gtertysh ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
int ft_is_prime(int nb)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = 2;
|
||
|
if (nb < 0)
|
||
|
return (0);
|
||
|
else if (nb < 3)
|
||
|
return (0);
|
||
|
else
|
||
|
{
|
||
|
while (i < nb / 2)
|
||
|
{
|
||
|
if (nb % i == 0)
|
||
|
return (0);
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
return (1);
|
||
|
}
|