-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_isprime.c
executable file
·31 lines (29 loc) · 1.15 KB
/
ft_isprime.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_isprime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/21 17:57:45 by akharrou #+# #+# */
/* Updated: 2019/02/21 17:58:11 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprime(int n)
{
int i;
if (n < 2)
return (0);
if (n == 2 || n == 3 || n == 5 || n == 7)
return (1);
if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n % 7 == 0)
return (0);
i = 7;
while ((i * i) <= n)
{
if (n % i == 0)
return (0);
i += 2;
}
return (1);
}