-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_is_prime.c
37 lines (33 loc) · 1.2 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
32
33
34
35
36
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lsauvage <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/29 12:39:27 by lsauvage #+# #+# */
/* Updated: 2018/01/04 15:10:45 by lsauvage ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** DESCRIPTION : verifie si l'entier passe en parametre est premier ou non.
**
** PARAM #1 : L'entier a tester.
**
** RETOUR : 1 si nb est premier, 0 sinon.
*/
int ft_is_prime(int nb)
{
int i;
i = 2;
if (nb <= 1)
return (0);
while (i <= nb / i)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}