commit
This commit is contained in:
26
C_Piscine_C_05/git/ex06/ft_is_prime.c
Normal file
26
C_Piscine_C_05/git/ex06/ft_is_prime.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_prime.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@student.42lausan> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/17 17:09:01 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/17 18:28:10 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_prime(int nb)
|
||||
{
|
||||
int r;
|
||||
int i;
|
||||
|
||||
if (nb == 0 || nb == 1)
|
||||
r = 0;
|
||||
else
|
||||
r = 1;
|
||||
i = 2;
|
||||
while (r > 0 && i < nb)
|
||||
r &= (nb % i++ != 0);
|
||||
return (r);
|
||||
}
|
||||
Reference in New Issue
Block a user