generated from github/welcome-to-github-and-pages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gaetan FAURE-LEVOUX
committed
Sep 18, 2019
1 parent
f5e439d
commit de818f9
Showing
9 changed files
with
143 additions
and
12 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.