-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_is_prime.c
31 lines (28 loc) · 1.11 KB
/
ft_is_prime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ngouy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/02/24 12:05:28 by ngouy #+# #+# */
/* Updated: 2015/11/04 15:29:09 by ngouy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** Return 1 if passed number is prime, 0 either
*/
int ft_is_prime(unsigned int i)
{
unsigned int cpt;
cpt = 3;
if (i % 2 == 0)
return (0);
while (cpt * cpt <= i)
{
if (i % cpt == 0)
return (0);
cpt++;
}
return (1);
}