40 lines
1.1 KiB
C
40 lines
1.1 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_find_next_prime.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2022/07/29 10:45:00 by ajoly #+# #+# */
|
||
|
/* Updated: 2022/08/01 15:57:50 by ajoly ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
int ft_is_prime(int nb)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = 2;
|
||
|
if (nb <= 1)
|
||
|
return (0);
|
||
|
while (i <= nb / i)
|
||
|
{
|
||
|
if (nb % i == 0)
|
||
|
return (0);
|
||
|
i++;
|
||
|
}
|
||
|
return (1);
|
||
|
}
|
||
|
|
||
|
int ft_find_next_prime(int nb)
|
||
|
{
|
||
|
int i;
|
||
|
|
||
|
i = nb;
|
||
|
while (ft_is_prime(i) != 1)
|
||
|
{
|
||
|
i++;
|
||
|
}
|
||
|
return (i);
|
||
|
}
|