commit
This commit is contained in:
32
C_05/git/ex07/ft_find_next_prime.c
Normal file
32
C_05/git/ex07/ft_find_next_prime.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_find_next_prime.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/18 10:53:52 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/18 14:03:38 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_find_next_prime(int nb)
|
||||
{
|
||||
int r;
|
||||
int i;
|
||||
|
||||
r = 0;
|
||||
while (r == 0)
|
||||
{
|
||||
if (nb <= 0 || nb == 1)
|
||||
r = 0;
|
||||
else
|
||||
r = 1;
|
||||
i = 2;
|
||||
while (r > 0 && i < nb)
|
||||
r &= (nb % i++ != 0);
|
||||
if (r == 0)
|
||||
nb++;
|
||||
}
|
||||
return (nb);
|
||||
}
|
||||
Reference in New Issue
Block a user