Piscine42

This commit is contained in:
2023-12-12 17:25:55 +01:00
commit e07184f084
62 changed files with 1572 additions and 0 deletions

18
C00/ex00/ft_putchar.c Executable file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/30 20:24:47 by fgras-ca #+# #+# */
/* Updated: 2022/12/01 17:49:23 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}

18
C00/ex01/ft_print_alphabet.c Executable file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/30 20:35:41 by fgras-ca #+# #+# */
/* Updated: 2022/12/01 19:28:23 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_alphabet(void)
{
write(1, "abcdefghijklmnopqrstuvwxyz", 26);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_reverse_alphabet.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/01 19:21:48 by fgras-ca #+# #+# */
/* Updated: 2022/12/01 19:27:48 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_reverse_alphabet(void)
{
write(1, "zyxwvutsrqponmlkjihgfedcba", 26);
}

18
C00/ex03/ft_print_numbers.c Executable file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_numbers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/01 19:36:44 by fgras-ca #+# #+# */
/* Updated: 2022/12/02 11:52:51 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_print_numbers(void)
{
write(1, "0123456789", 10);
}

25
C00/ex04/ft_is_negative.c Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_negative.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/01 19:42:52 by fgras-ca #+# #+# */
/* Updated: 2022/12/02 11:57:31 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_is_negative(int n)
{
if (n < 0)
{
write(1, "N", 1);
}
else
{
write(1, "P", 1);
}
}

BIN
C00/fr.subject .pdf Normal file

Binary file not shown.

16
C01/ex00/ft_ft.c Executable file
View File

@@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/03 18:27:18 by fgras-ca #+# #+# */
/* Updated: 2022/12/05 15:43:03 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ft(int *nbr)
{
*nbr = 42;
}

16
C01/ex01/ft_ultimate_ft.c Executable file
View File

@@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 15:48:06 by fgras-ca #+# #+# */
/* Updated: 2022/12/08 10:13:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_ft(int *********nbr)
{
*********nbr = 42;
}

20
C01/ex02/ft_swap.c Executable file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 15:50:26 by fgras-ca #+# #+# */
/* Updated: 2022/12/05 15:54:58 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int swap;
swap = *a;
*a = *b;
*b = swap;
}

17
C01/ex03/ft_div_mod.c Executable file
View File

@@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 15:57:30 by fgras-ca #+# #+# */
/* Updated: 2022/12/07 09:17:14 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
void ft_div_mod(int a, int b, int *div, int *mod)
{
*div = a / b;
*mod = a % b;
}

20
C01/ex04/ft_ultimate_div_mod.c Executable file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 16:55:09 by fgras-ca #+# #+# */
/* Updated: 2022/12/07 09:50:31 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_div_mod(int *a, int *b)
{
int swap;
swap = *a;
*a = swap / *b;
*b = swap % *b;
}

25
C01/ex05/ft_putstr.c Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 17:08:21 by fgras-ca #+# #+# */
/* Updated: 2022/12/07 12:42:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
int a;
a = 0;
while (str[a] != '\0')
{
write(1, &str[a], 1);
a++;
}
}

23
C01/ex06/ft_strlen.c Executable file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 11:01:26 by fgras-ca #+# #+# */
/* Updated: 2022/12/07 12:40:42 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int a;
a = 0;
while (str[a] != '\0')
{
a++;
}
return (a);
}

BIN
C01/fr.subject.pdf Normal file

Binary file not shown.

25
C02/ex00/ft_strcpy.c Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 12:44:06 by fgras-ca #+# #+# */
/* Updated: 2022/12/10 10:29:05 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}

29
C02/ex01/ft_strncpy.c Executable file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 13:20:04 by fgras-ca #+# #+# */
/* Updated: 2022/12/10 16:55:53 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (src[i] != '\0' && i < n)
{
dest[i] = src[i];
i++;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}

BIN
C02/ex02/.main.c.swp Executable file

Binary file not shown.

34
C02/ex02/ft_str_is_alpha.c Executable file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_alpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 14:06:49 by fgras-ca #+# #+# */
/* Updated: 2022/12/10 17:05:15 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_alpha(char *str)
{
int i;
i = 0;
if (str[i] == '\0')
{
return (1);
}
while (str[i] != '\0')
{
if ((str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122))
{
i++;
}
else
{
return (0);
}
}
return (1);
}

34
C02/ex03/ft_str_is_numeric.c Executable file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_numeric.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 17:46:52 by fgras-ca #+# #+# */
/* Updated: 2022/12/10 17:06:15 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_numeric(char *str)
{
int i;
i = 0;
if (str[i] == '\0')
{
return (1);
}
while (str[i] != '\0')
{
if ((str[i] >= 48 && str[i] <= 57))
{
i++;
}
else
{
return (0);
}
}
return (1);
}

34
C02/ex04/ft_str_is_lowercase.c Executable file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_lowercase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 18:03:49 by fgras-ca #+# #+# */
/* Updated: 2022/12/07 18:11:53 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_lowercase(char *str)
{
int i;
i = 0;
if (str[i] == '\0')
{
return (1);
}
while (str[i] != '\0')
{
if ((str[i]) >= 97 && (str[i] <= 122))
{
i++;
}
else
{
return (0);
}
}
return (1);
}

34
C02/ex05/ft_str_is_uppercase.c Executable file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_uppercase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 18:13:20 by fgras-ca #+# #+# */
/* Updated: 2022/12/08 08:12:15 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_uppercase(char *str)
{
int i;
i = 0;
if (str[i] == 0)
{
return (1);
}
while (str[i] != '\0')
{
if ((str[i] >= 65 && str[i] <= 90))
{
i++;
}
else
{
return (0);
}
}
return (1);
}

30
C02/ex06/ft_str_is_printable.c Executable file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_printable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/07 18:30:32 by fgras-ca #+# #+# */
/* Updated: 2022/12/08 08:26:33 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_printable(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
if ((str[i] >= 32 && str[i] <= 126))
{
i++;
}
else
{
return (0);
}
}
return (1);
}

BIN
C02/ex07/.main.c.swo Executable file

Binary file not shown.

25
C02/ex07/ft_strupcase.c Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strupcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/08 08:28:11 by fgras-ca #+# #+# */
/* Updated: 2022/12/10 11:01:18 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strupcase(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
if ((str[i] >= 97 && str[i] <= 122))
str[i] -= 32;
i++;
}
return (str);
}

BIN
C02/ex08/.main.c.swp Executable file

Binary file not shown.

25
C02/ex08/ft_strlowcase.c Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlowcase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/08 10:34:31 by fgras-ca #+# #+# */
/* Updated: 2022/12/08 10:44:36 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strlowcase(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
if ((str[i] >= 65 && str[i] <= 90))
str[i] += 32;
i++;
}
return (str);
}

BIN
C02/fr.subject.pdf Normal file

Binary file not shown.

23
C03/ex00/ft_strcmp.c Executable file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 06:53:45 by fgras-ca #+# #+# */
/* Updated: 2022/12/09 08:31:32 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while ((s1[i] == s2[i]) && ((s1[i] != '\0') || (s2[i] != '\0')))
{
i++;
}
return (s1[i] - s2[i]);
}

27
C03/ex01/ft_strncmp.c Executable file
View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 08:08:10 by fgras-ca #+# #+# */
/* Updated: 2022/12/10 13:40:02 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
unsigned int i;
i = 0;
if (n == 0)
{
return (0);
}
while (s1[i] == s2[i] && (s1[i] != '\0' || s2[i] != '\0') && i < (n -1))
{
i++;
}
return (s1[i] - s2[i]);
}

39
C03/ex02/ft_strcat.c Executable file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/09 09:45:42 by fgras-ca #+# #+# */
/* Updated: 2022/12/10 16:13:32 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return (i);
}
char *ft_strcat(char *dest, char *src)
{
int i;
int dest_len;
i = 0;
dest_len = ft_strlen(dest);
while (src[i] != '\0')
{
dest[dest_len + i] = src[i];
i++;
}
dest[dest_len + i] = '\0';
return (dest);
}

39
C03/ex03/ft_strncat.c Executable file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/10 16:23:52 by fgras-ca #+# #+# */
/* Updated: 2022/12/12 18:33:50 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
{
i++;
}
return (i);
}
char *ft_strncat(char *dest, char *src, unsigned int nb)
{
unsigned int i;
unsigned int dest_len;
i = 0;
dest_len = ft_strlen(dest);
while (src[i] && i < nb)
{
dest[dest_len + i] = src[i];
i++;
}
dest[dest_len + i] = '\0';
return (dest);
}

BIN
C03/fr.subject.pdf Normal file

Binary file not shown.

21
C04/ex00/ft_strlen.c Executable file
View File

@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/11 13:04:29 by fgras-ca #+# #+# */
/* Updated: 2022/12/11 13:06:17 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}

25
C04/ex01/ft_putstr.c Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/11 13:08:32 by fgras-ca #+# #+# */
/* Updated: 2022/12/13 11:22:07 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
write(1, &str[i], 1);
i++;
}
}

40
C04/ex02/ft_putnbr.c Executable file
View File

@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/11 14:02:07 by fgras-ca #+# #+# */
/* Updated: 2022/12/11 17:23:13 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int nb)
{
if (nb == -2147483648)
{
write(1, "-2147483648", 11);
}
else if (nb >= 0 && nb < 10)
{
ft_putchar(nb + 48);
}
else if (nb < 0)
{
ft_putchar('-');
ft_putnbr(nb * (-1));
}
else
{
ft_putnbr (nb / 10);
ft_putnbr (nb % 10);
}
}

36
C04/ex03/ft_atoi.c Executable file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 10:11:50 by fgras-ca #+# #+# */
/* Updated: 2022/12/13 11:01:40 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int res;
int sign;
int i;
i = 0;
res = 0;
sign = 1;
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
while (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
sign *= (-1);
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
res = res * 10 + str[i] - '0';
i++;
}
return (res * sign);
}

BIN
C04/fr.subject.pdf Normal file

Binary file not shown.

View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 09:44:26 by fgras-ca #+# #+# */
/* Updated: 2022/12/12 11:00:06 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_factorial(int nb)
{
int resultat;
resultat = 1;
if (nb == 0)
{
return (1);
}
while (nb > 0)
{
resultat *= nb;
nb--;
}
if (nb < 0)
{
return (0);
}
return (resultat);
}

View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 11:02:42 by fgras-ca #+# #+# */
/* Updated: 2022/12/12 11:17:18 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
if (nb < 0)
return (0);
if (nb == 0)
return (1);
return (nb * ft_recursive_factorial(nb - 1));
}

36
C05/ex02/ft_iterative_power.c Executable file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 11:42:46 by fgras-ca #+# #+# */
/* Updated: 2022/12/12 12:13:42 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int resultat;
int i;
i = 0;
resultat = 1;
if (power == 0)
return (1);
if (nb == 0 && power == 0)
{
return (1);
}
if (power < 0)
{
return (0);
}
while (i < power)
{
resultat *= nb;
i++;
}
return (resultat);
}

25
C05/ex03/ft_recursive_power.c Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 12:17:25 by fgras-ca #+# #+# */
/* Updated: 2022/12/12 13:20:33 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_power(int nb, int power)
{
if (nb == 0 && power == 0)
return (1);
if (power < 0)
return (0);
if (power == 0)
return (1);
else if (power == 1)
return (nb);
else
return (nb * ft_recursive_power(nb, power -1));
}

20
C05/ex04/ft_fibonacci.c Executable file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fibonacci.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 13:26:04 by fgras-ca #+# #+# */
/* Updated: 2022/12/12 14:22:37 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_fibonacci(int index)
{
if (index < 0)
return (-1);
if (index == 0 || index == 1)
return (index);
return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2));
}

35
C05/ex05/ft_sqrt.c Executable file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 16:05:20 by fgras-ca #+# #+# */
/* Updated: 2022/12/14 15:58:40 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_sqrt(int nb)
{
int i;
if (nb < 0)
{
return (0);
}
if (nb == 1)
{
return (1);
}
i = 1;
while (i < nb / i && i < 46341)
{
i++;
}
if (i * i == nb)
{
return (i);
}
return (0);
}

30
C05/ex06/ft_is_prime.c Executable file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/12 18:55:02 by fgras-ca #+# #+# */
/* Updated: 2022/12/13 13:38:38 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
if (nb <= 1)
return (0);
while (i <= nb / 2)
{
if (nb % i == 0)
{
return (0);
}
else
i++;
}
return (1);
}

BIN
C05/fr.subject.pdf Normal file

Binary file not shown.

View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_program_name.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 14:01:59 by fgras-ca #+# #+# */
/* Updated: 2022/12/13 14:56:15 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
write(1, &str[i], 1);
i++;
}
}
int main(int argc, char **argv)
{
if (argc > 0)
{
ft_putstr(argv[0]);
ft_putchar('\n');
}
}

46
C06/ex01/ft_print_params.c Executable file
View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 14:01:59 by fgras-ca #+# #+# */
/* Updated: 2022/12/13 15:39:06 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
write(1, &str[i], 1);
i++;
}
}
int main(int argc, char **argv)
{
int i;
i = 1;
while (argv[i])
{
if (argc > 1)
{
ft_putstr(argv[i]);
ft_putchar('\n');
i++;
}
}
}

43
C06/ex02/ft_rev_params.c Executable file
View File

@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 14:01:59 by fgras-ca #+# #+# */
/* Updated: 2022/12/13 16:48:28 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
write(1, &str[i], 1);
i++;
}
}
int main(int argc, char **argv)
{
int i;
i = argc -1;
while (i > 0)
{
ft_putstr(argv[i]);
ft_putchar('\n');
i--;
}
}

69
C06/ex03/ft_sort_params.c Executable file
View File

@@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 16:50:23 by fgras-ca #+# #+# */
/* Updated: 2022/12/14 09:36:30 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
write(1, &str[i], 1);
i++;
}
}
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while ((s1[i] == s2[i]) && ((s1[i] != '\0') || (s2[i] != '\0')))
{
i++;
}
return (s1[i] - s2[i]);
}
int main(int argc, char **argv)
{
int i;
char *swap;
i = 1;
while (i < argc -1)
{
if (ft_strcmp(argv[i], argv[i + 1]) > 0)
{
swap = argv[i];
argv[i] = argv[i + 1];
argv[i +1] = swap;
i = 0;
}
i++;
}
i = 1;
while (i < argc)
{
ft_putstr(argv[i]);
ft_putchar('\n');
i++;
}
return (0);
}

BIN
C06/fr.subject.pdf Normal file

Binary file not shown.

43
C07/ex00/ft_strdup.c Executable file
View File

@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/14 13:53:46 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 08:21:14 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strdup(char *src)
{
char *copy;
int i;
i = 0;
copy = (char *) malloc(sizeof(char) * (ft_strlen(src) + 1));
if (copy == 0)
{
return (0);
}
while (src [i])
{
copy[i] = src[i];
i++;
}
copy[i] = '\0';
return (copy);
}

36
C07/ex01/ft_range.c Executable file
View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/14 16:38:46 by fgras-ca #+# #+# */
/* Updated: 2022/12/15 10:05:03 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_range(int min, int max)
{
int *tab;
int i;
if (min >= max)
{
return (0);
}
tab = (int *) malloc(sizeof(int) * (max - min));
if (tab == 0)
{
return (0);
}
i = 0;
while (i < max - min)
{
tab[i] = min + i;
i++;
}
return (tab);
}

54
C07/ex02/ft_ultimate_range.c Executable file
View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/14 17:31:36 by fgras-ca #+# #+# */
/* Updated: 2022/12/15 10:48:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_range(int min, int max)
{
int *tab;
int i;
if (min >= max)
{
return (0);
}
tab = (int *) malloc(sizeof(int) * (max - min));
if (tab == 0)
{
return (0);
}
i = 0;
while (i < max - min)
{
tab[i] = min + i;
i++;
}
return (tab);
}
int ft_ultimate_range(int **range, int min, int max)
{
if (min >= max)
{
*range = 0;
return (0);
}
else
{
*range = ft_range(min, max);
if (*range == 0)
{
return (-1);
}
}
return (max - min);
}

88
C07/ex03/ft_strjoin.c Executable file
View File

@@ -0,0 +1,88 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 10:50:07 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 11:45:43 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strcat(char *dest, char *src)
{
int i;
int dest_len;
i = 0;
dest_len = ft_strlen(dest);
while (src[i] != '\0')
{
dest[dest_len + i] = src[i];
i++;
}
dest[dest_len + i] = '\0';
return (dest);
}
int malloc_size(int size, char **strs, char *sep)
{
int i;
int resultat;
if (size == 0)
{
return (1);
}
i = 0;
resultat = 0;
while (i < size)
{
resultat += ft_strlen(strs[i]);
i++;
}
resultat += ft_strlen(sep) * (size - 1);
return (resultat + 1);
}
char *ft_strjoin(int size, char **strs, char *sep)
{
char *resultat;
int i;
resultat = malloc((sizeof(char)) * malloc_size(size, strs, sep));
if (resultat == 0)
{
return (0);
}
resultat[0] = 0;
if (size == 0)
{
return (resultat);
}
i = 0;
while (i < size)
{
ft_strcat(resultat, strs[i]);
if (i != size -1)
{
ft_strcat(resultat, sep);
}
i++;
}
resultat[ft_strlen(resultat)] = '\0';
return (resultat);
}

BIN
C07/fr.subject.pdf Normal file

Binary file not shown.

25
C08/ex01/ft_boolean.h Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_boolean.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/15 14:30:45 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 12:24:26 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_BOOLEAN_H
# define FT_BOOLEAN_H
# include <unistd.h>
# define EVEN(n) n % 2 == 0
typedef int t_bool;
# define FALSE 0
# define TRUE 1
# define EVEN_MSG "I have an even number of arguments.\n"
# define ODD_MSG "I have an odd number of arguments.\n"
# define SUCCESS 0
#endif

16
C08/ex02/ft_abs.h Executable file
View File

@@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_abs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 12:25:59 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 12:40:44 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_ABS_H
# define FT_ABS_H
# define ABS(x) (((x) < 0) ? -(x) : (x))
#endif

20
C08/ex03/ft_point.h Executable file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_point.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 12:51:34 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 12:53:57 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_POINT_H
# define FT_POINT_H
typedef struct point{
int x;
int y;
}t_point;
#endif

68
C08/ex04/ft_strs_to_tab.c Executable file
View File

@@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strs_to_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/21 09:54:48 by fgras-ca #+# #+# */
/* Updated: 2022/12/21 11:15:13 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_stock_str.h"
#include <stdlib.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strdup(char *src)
{
char *dest;
int i;
i = 0;
dest = (char *) malloc(sizeof(char) * (ft_strlen(src) + 1));
if (dest == 0)
{
return (0);
}
while (src[i])
{
dest[i] = src[i];
i++;
}
dest[i] = 0;
return (dest);
}
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
{
int i;
t_stock_str *tab;
if (ac < 1)
ac = 0;
tab = malloc(sizeof(t_stock_str) * (ac + 1));
if (tab == 0)
{
return (0);
}
i = 0;
while (i < ac)
{
tab[i].size = ft_strlen (av[i]);
tab[i].str = av[i];
tab[i].copy = ft_strdup (tab[i].str);
i++;
}
tab[i].str = 0;
return (tab);
}

72
C08/ex05/ft_show_tab.c Executable file
View File

@@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_show_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/21 10:43:27 by fgras-ca #+# #+# */
/* Updated: 2022/12/21 11:44:58 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "ft_stock_str.h"
struct s_stock_str *ft_strs_to_tab(int ac, char **av);
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
write(1, &str[i], 1);
i++;
}
}
void ft_putnbr(int nb)
{
if (nb == -2147483648)
{
write(1, "-2147483648", 11);
}
else if (nb >= 0 && nb < 10)
{
ft_putchar(nb + 48);
}
else if (nb < 0)
{
ft_putchar('-');
ft_putnbr(nb * (-1));
}
else
{
ft_putnbr (nb / 10);
ft_putnbr (nb % 10);
}
}
void ft_show_tab(struct s_stock_str *par)
{
int i;
i = 0;
while (par[i].str)
{
ft_putstr(par[i].str);
ft_putchar('\n');
ft_putnbr(par[i].size);
ft_putchar('\n');
ft_putstr(par[i].copy);
ft_putchar('\n');
i++;
}
}

BIN
C08/fr.subject.pdf Normal file

Binary file not shown.

1
rush00 Submodule

Submodule rush00 added at f7ebcfcccd