1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
42-2nd-piscine/C05/ex07/ft_find_next_prime.c
2023-08-03 23:16:27 +02:00

44 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_find_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/23 23:24:05 by adjoly #+# #+# */
/* Updated: 2023/07/31 09:59:29 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
if (nb == 2147483647)
return (1);
if (nb <= 0 || nb == 1)
return (0);
if (nb % 2 == 0)
return (0);
while (i < nb / 2)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}
int ft_find_next_prime(int nb)
{
int i;
i = nb;
if (nb <= 2)
return (2);
while (ft_is_prime(i) != 1)
i++;
return (i);
}