38 lines
1.1 KiB
C
38 lines
1.1 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_find_next_prime.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2022/07/20 14:31:43 by cchauvet #+# #+# */
|
||
|
/* Updated: 2022/07/28 20:17:40 by cchauvet ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
int ft_is_prime(int nb)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = 2;
|
||
|
while (i <= nb / i)
|
||
|
{
|
||
|
if (nb % i == 0)
|
||
|
return (0);
|
||
|
i++;
|
||
|
}
|
||
|
return (1);
|
||
|
}
|
||
|
|
||
|
int ft_find_next_prime(int nb)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
if (nb < 2)
|
||
|
return (2);
|
||
|
i = nb;
|
||
|
while (ft_is_prime(i) == 0)
|
||
|
i++;
|
||
|
return (i);
|
||
|
}
|