Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetan FAURE-LEVOUX committed Sep 18, 2019
1 parent f5e439d commit de818f9
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 12 deletions.
Binary file modified C05/ex07/a.out
Binary file not shown.
63 changes: 63 additions & 0 deletions C05/ex07/ft_find_next_prim777e.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gfaure-l <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdio.h>
int main()
{
printf("%d\n", ft_next_prime(2147483647));
return (0);
}

13 changes: 5 additions & 8 deletions C05/ex07/ft_find_next_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: gfaure-l <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand All @@ -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)
Expand All @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions C07/ex00/ft_strdup.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
/* By: gfaure-l <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
#include <string.h>
#include <stdio.h>

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;
Expand Down
Binary file added C07/ex01/a.out
Binary file not shown.
34 changes: 33 additions & 1 deletion C07/ex01/ft_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,42 @@
/* By: gfaure-l <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>

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 <stdio.h>
int main()
{
int n = 0;
int *ta;
ta = ft_range(2,9);
while (ta[n])
{
printf("%d\n", ta[n]);
n++;
}
}
39 changes: 39 additions & 0 deletions C07/ex02/ft_ultimate_range.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gfaure-l <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/18 14:15:02 by gfaure-l #+# #+# */
/* Updated: 2019/09/18 15:22:57 by gfaure-l ### ########.fr */
/* */
/* ************************************************************************** */

#include <stdlib.h>

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);
}
Binary file added C07/ex02/ft_ultimate_range.o
Binary file not shown.
Binary file added Screen Shot 2019-09-18 at 3.00.00 PM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de818f9

Please sign in to comment.