first commit
This commit is contained in:
BIN
C05/ex06/.ft_is_prime.c.swp
Normal file
BIN
C05/ex06/.ft_is_prime.c.swp
Normal file
Binary file not shown.
29
C05/ex06/ft_is_prime.c
Normal file
29
C05/ex06/ft_is_prime.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_prime.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/07/23 23:24:05 by adjoly #+# #+# */
|
||||
/* Updated: 2023/08/02 10:20:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_prime(int nb)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (nb <= 0 || nb == 1)
|
||||
return (0);
|
||||
i = 2;
|
||||
if (nb == 2)
|
||||
return (1);
|
||||
while (i < nb / 2)
|
||||
{
|
||||
if (nb % i == 0)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
Reference in New Issue
Block a user