first commit
This commit is contained in:
39
ended/C05/ex07/ft_find_next_prime.c
Normal file
39
ended/C05/ex07/ft_find_next_prime.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
Reference in New Issue
Block a user