diff --git a/C05/ex07/a.out b/C05/ex07/a.out index e0f203b..3dd1dc3 100755 Binary files a/C05/ex07/a.out and b/C05/ex07/a.out differ diff --git a/C05/ex07/ft_find_next_prim777e.c b/C05/ex07/ft_find_next_prim777e.c new file mode 100644 index 0000000..0a56003 --- /dev/null +++ b/C05/ex07/ft_find_next_prim777e.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_next_prime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gfaure-l +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/09/15 15:50:25 by gfaure-l #+# #+# */ +/* Updated: 2019/09/17 23:25:18 by gfaure-l ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_sqrt(int nb) +{ + long i; + long j; + + j = nb; + i = 1; + if (j < 0) + return (0); + while (i * i < j) + i++; + return (i); +} + +int ft_is_prime(int nb) +{ + int i; + + i = 2; + if (nb < 2) + return (0); + if (nb == 2 || nb == 3) + return (1); + if (nb > 25000) + nb = ft_sqrt(nb); + while (nb % i != 0 && i < (nb - 1)) + i++; + if (nb % i == 0) + return (0); + return (1); +} + +int ft_next_prime(int nb) +{ + while (ft_is_prime(nb) == 0) + nb++; + if (ft_is_prime(nb) == 1) + return (nb); + return (0); +} + + + + +#include +int main() +{ + printf("%d\n", ft_next_prime(2147483647)); + return (0); +} + diff --git a/C05/ex07/ft_find_next_prime.c b/C05/ex07/ft_find_next_prime.c index 0a56003..4be3c63 100644 --- a/C05/ex07/ft_find_next_prime.c +++ b/C05/ex07/ft_find_next_prime.c @@ -6,7 +6,7 @@ /* By: gfaure-l +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/09/15 15:50:25 by gfaure-l #+# #+# */ -/* Updated: 2019/09/17 23:25:18 by gfaure-l ### ########.fr */ +/* Updated: 2019/09/18 11:13:27 by gfaure-l ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,14 +27,11 @@ int ft_sqrt(int nb) int ft_is_prime(int nb) { int i; + long racine; i = 2; - if (nb < 2) - return (0); - if (nb == 2 || nb == 3) - return (1); if (nb > 25000) - nb = ft_sqrt(nb); + racine = ft_sqrt(nb); while (nb % i != 0 && i < (nb - 1)) i++; if (nb % i == 0) @@ -44,10 +41,10 @@ int ft_is_prime(int nb) int ft_next_prime(int nb) { + if (nb < 2) + return (2); while (ft_is_prime(nb) == 0) nb++; - if (ft_is_prime(nb) == 1) - return (nb); return (0); } diff --git a/C07/ex00/ft_strdup.c b/C07/ex00/ft_strdup.c index 572e05f..c86d338 100644 --- a/C07/ex00/ft_strdup.c +++ b/C07/ex00/ft_strdup.c @@ -6,18 +6,18 @@ /* By: gfaure-l +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/09/17 12:46:04 by gfaure-l #+# #+# */ -/* Updated: 2019/09/17 17:21:01 by gfaure-l ### ########.fr */ +/* Updated: 2019/09/18 14:42:03 by gfaure-l ### ########.fr */ /* */ /* ************************************************************************** */ #include -#include -#include void *ft_strdup(char *src) { char *ptr = NULL; ptr = malloc(7 * sizeof(char)); + if (ptr == NULL) + return (0); ptr = src; printf("malloc : %s\n", ptr); return 0; diff --git a/C07/ex01/a.out b/C07/ex01/a.out new file mode 100755 index 0000000..f45dad7 Binary files /dev/null and b/C07/ex01/a.out differ diff --git a/C07/ex01/ft_range.c b/C07/ex01/ft_range.c index 5845103..b2cda06 100644 --- a/C07/ex01/ft_range.c +++ b/C07/ex01/ft_range.c @@ -6,10 +6,42 @@ /* By: gfaure-l +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/09/17 23:33:47 by gfaure-l #+# #+# */ -/* Updated: 2019/09/17 23:36:29 by gfaure-l ### ########.fr */ +/* Updated: 2019/09/18 14:41:28 by gfaure-l ### ########.fr */ /* */ /* ************************************************************************** */ +#include + int *ft_range(int min, int max) { + int *tab = NULL; + int i; + + if (min >= max) + return (0); + i = 0; + tab = malloc((max - min) * sizeof(char)); + if (tab == NULL) + return (0); + while (max > min) + { + tab[i] = min; + min++; + i++; + } + return (tab); +} + +#include +int main() +{ + int n = 0; + int *ta; + ta = ft_range(2,9); + while (ta[n]) + { + printf("%d\n", ta[n]); + n++; + } +} diff --git a/C07/ex02/ft_ultimate_range.c b/C07/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..4509d69 --- /dev/null +++ b/C07/ex02/ft_ultimate_range.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gfaure-l +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/09/18 14:15:02 by gfaure-l #+# #+# */ +/* Updated: 2019/09/18 15:22:57 by gfaure-l ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_ultimate_range(int **range, int min, int max) +{ + int *tab = NULL; + int i; + + if (min >= max) + { + return (0); + range = NULL; + } + i = 0; + tab = malloc((max - min) * sizeof(int)); + if (tab == NULL) + return (0); + while (max > min) + { + tab[i] = min; + min++; + i++; + } + *range = tab; + if (**range != (max - min)) + return (-1); + return (i); +} diff --git a/C07/ex02/ft_ultimate_range.o b/C07/ex02/ft_ultimate_range.o new file mode 100644 index 0000000..8972734 Binary files /dev/null and b/C07/ex02/ft_ultimate_range.o differ diff --git a/Screen Shot 2019-09-18 at 3.00.00 PM.png b/Screen Shot 2019-09-18 at 3.00.00 PM.png new file mode 100644 index 0000000..a9bb45d Binary files /dev/null and b/Screen Shot 2019-09-18 at 3.00.00 PM.png differ