Exos
This commit is contained in:
58
ex0/ft_ft.c
Normal file
58
ex0/ft_ft.c
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ft.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/09 16:50:01 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/09 17:31:41 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*void ft_putnbr(int nb)
|
||||||
|
{
|
||||||
|
char value;
|
||||||
|
if (nb == -2147483648)
|
||||||
|
{
|
||||||
|
write(1, "-2147483648", 11);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
write(1, "-", 1);
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb > 9)
|
||||||
|
{
|
||||||
|
ft_putnbr(nb / 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = nb % 10 + '0';
|
||||||
|
write(1, &value, 1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void ft_ft(int *nbr)
|
||||||
|
{
|
||||||
|
*nbr = 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main(void)
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
int *ptr1;
|
||||||
|
|
||||||
|
a = 0;
|
||||||
|
ptr1 = &a;
|
||||||
|
|
||||||
|
write(1, "Avant : ", 8);
|
||||||
|
ft_putnbr(a);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Apres : ", 8);
|
||||||
|
ft_ft(ptr1);
|
||||||
|
ft_putnbr(*ptr1);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
return (0);
|
||||||
|
}*/
|
||||||
74
ex1/ft_ultimate_ft.c
Normal file
74
ex1/ft_ultimate_ft.c
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ultimate_ft.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/09 16:52:51 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/09 17:29:03 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*void ft_putnbr(int nb)
|
||||||
|
{
|
||||||
|
char value;
|
||||||
|
if (nb == -2147483648)
|
||||||
|
{
|
||||||
|
write(1, "-2147483648", 11);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
write(1, "-", 1);
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb > 9)
|
||||||
|
{
|
||||||
|
ft_putnbr(nb / 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
value = nb % 10 + '0';
|
||||||
|
write(1, &value, 1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void ft_ultimate_ft(int *********nbr)
|
||||||
|
{
|
||||||
|
*********nbr = 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main(void)
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
int *ptr1;
|
||||||
|
int **ptr2;
|
||||||
|
int ***ptr3;
|
||||||
|
int ****ptr4;
|
||||||
|
int *****ptr5;
|
||||||
|
int ******ptr6;
|
||||||
|
int *******ptr7;
|
||||||
|
int ********ptr8;
|
||||||
|
int *********ptr9;
|
||||||
|
|
||||||
|
a = 0;
|
||||||
|
ptr1 = &a;
|
||||||
|
ptr2 = &ptr1;
|
||||||
|
ptr3 = &ptr2;
|
||||||
|
ptr4 = &ptr3;
|
||||||
|
ptr5 = &ptr4;
|
||||||
|
ptr6 = &ptr5;
|
||||||
|
ptr7 = &ptr6;
|
||||||
|
ptr8 = &ptr7;
|
||||||
|
ptr9 = &ptr8;
|
||||||
|
|
||||||
|
write(1, "Avant : ", 8);
|
||||||
|
ft_putnbr(a);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Apres : ", 8);
|
||||||
|
ft_ultimate_ft(ptr9);
|
||||||
|
ft_putnbr(*********ptr9);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
return (0);
|
||||||
|
}*/
|
||||||
68
ex2/ft_swap.c
Normal file
68
ex2/ft_swap.c
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_swap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/09 17:36:15 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/09 17:46:32 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*void ft_putnbr(int nb)
|
||||||
|
{
|
||||||
|
char value;
|
||||||
|
|
||||||
|
if (nb == -2147483648)
|
||||||
|
{
|
||||||
|
write(1, "-2147483648", 11);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
write(1, "-", 1);
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb > 9)
|
||||||
|
{
|
||||||
|
ft_putnbr(nb / 10);
|
||||||
|
}
|
||||||
|
value = nb % 10 + '0';
|
||||||
|
write(1, &value, 1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void ft_swap(int *a, int *b)
|
||||||
|
{
|
||||||
|
int tmp;
|
||||||
|
|
||||||
|
tmp = *a;
|
||||||
|
*a = *b;
|
||||||
|
*b = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main(void)
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
|
||||||
|
a = 3;
|
||||||
|
b = 9;
|
||||||
|
write(1, "Avant - a: ", 11);
|
||||||
|
ft_putnbr(a);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Avant - b: ", 11);
|
||||||
|
ft_putnbr(b);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
ft_swap(&a, &b);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Apres - a: ", 11);
|
||||||
|
ft_putnbr(a);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Apres - b: ", 11);
|
||||||
|
ft_putnbr(b);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
return (0);
|
||||||
|
}*/
|
||||||
62
ex3/ft_div_mod.c
Normal file
62
ex3/ft_div_mod.c
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_div_mod.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/09 17:52:58 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/09 18:50:17 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*void ft_putnbr(int nb)
|
||||||
|
{
|
||||||
|
char value;
|
||||||
|
|
||||||
|
if (nb == -2147483648)
|
||||||
|
{
|
||||||
|
write(1, "-2147483648", 11);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
write(1, "-", 1);
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb > 9)
|
||||||
|
{
|
||||||
|
ft_putnbr(nb / 10);
|
||||||
|
}
|
||||||
|
value = nb % 10 + '0';
|
||||||
|
write(1, &value, 1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void ft_div_mod(int a, int b, int *div, int *mod)
|
||||||
|
{
|
||||||
|
*div = a / b;
|
||||||
|
*mod = a % b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main(void)
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
int res_div;
|
||||||
|
int res_mod;
|
||||||
|
|
||||||
|
a = 42;
|
||||||
|
b = 5;
|
||||||
|
res_div = 0;
|
||||||
|
res_mod = 0;
|
||||||
|
ft_div_mod(a, b, &res_div, &res_mod);
|
||||||
|
write(1, "Division de 42 par 5 :\n", 23);
|
||||||
|
write(1, "Quotient : ", 11);
|
||||||
|
ft_putnbr(res_div);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Reste : ", 8);
|
||||||
|
ft_putnbr(res_mod);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
}*/
|
||||||
68
ex4/ft_ultimate_div_mod.c
Normal file
68
ex4/ft_ultimate_div_mod.c
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ultimate_div_mod.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/09 18:53:55 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/09 19:05:23 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*void ft_putnbr(int nb)
|
||||||
|
{
|
||||||
|
char value;
|
||||||
|
|
||||||
|
if (nb == -2147483648)
|
||||||
|
{
|
||||||
|
write(1, "-2147483648", 11);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
write(1, "-", 1);
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb > 9)
|
||||||
|
{
|
||||||
|
ft_putnbr(nb / 10);
|
||||||
|
}
|
||||||
|
value = nb % 10 + '0';
|
||||||
|
write(1, &value, 1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void ft_ultimate_div_mod(int *a, int *b)
|
||||||
|
{
|
||||||
|
int temp_a;
|
||||||
|
int temp_b;
|
||||||
|
|
||||||
|
temp_a = *a;
|
||||||
|
temp_b = *b;
|
||||||
|
*a = temp_a / temp_b;
|
||||||
|
*b = temp_a % temp_b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main(void)
|
||||||
|
{
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
|
||||||
|
a = 42;
|
||||||
|
b = 5;
|
||||||
|
write(1, "Avant : ", 8);
|
||||||
|
ft_putnbr(a);
|
||||||
|
write(1, " et ", 4);
|
||||||
|
ft_putnbr(b);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
ft_ultimate_div_mod(&a, &b);
|
||||||
|
write(1, "Apres (Div) : ", 14);
|
||||||
|
ft_putnbr(a);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Apres (Mod) : ", 14);
|
||||||
|
ft_putnbr(b);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
return (0);
|
||||||
|
}*/
|
||||||
76
ex5/ft_rev_int_tab.c
Normal file
76
ex5/ft_rev_int_tab.c
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_rev_int_tab.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/09 19:08:40 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/09 19:23:29 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*void ft_putnbr(int nb)
|
||||||
|
{
|
||||||
|
char value;
|
||||||
|
|
||||||
|
if (nb == -2147483648)
|
||||||
|
{
|
||||||
|
write(1, "-2147483648", 11);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
write(1, "-", 1);
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb > 9)
|
||||||
|
{
|
||||||
|
ft_putnbr(nb / 10);
|
||||||
|
}
|
||||||
|
value = nb % 10 + '0';
|
||||||
|
write(1, &value, 1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void ft_rev_int_tab(int *tab, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int temp;
|
||||||
|
int last;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
last = size - 1;
|
||||||
|
while (i < size / 2)
|
||||||
|
{
|
||||||
|
temp = tab[i];
|
||||||
|
tab[i] = tab[last];
|
||||||
|
tab[last] = temp;
|
||||||
|
i++;
|
||||||
|
last--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main(void)
|
||||||
|
{
|
||||||
|
int tab[5] = {1, 2, 3, 4, 5};
|
||||||
|
int size;
|
||||||
|
|
||||||
|
size = 5;
|
||||||
|
write(1, "Avant : 1, 2, 3, 4, 5", 22);
|
||||||
|
ft_rev_int_tab(tab, size);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
write(1, "Apres : ", 8);
|
||||||
|
ft_putnbr(tab[0]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[1]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[2]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[3]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[4]);
|
||||||
|
write(1, "\n", 1);
|
||||||
|
return (0);
|
||||||
|
}*/
|
||||||
87
ex6/ft_sort_int_tab.c
Normal file
87
ex6/ft_sort_int_tab.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_sort_int_tab.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: lclerel- <lclerel-@learner.42.tech> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/03/09 19:24:29 by lclerel- #+# #+# */
|
||||||
|
/* Updated: 2026/03/09 19:34:56 by lclerel- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*void ft_putnbr(int nb)
|
||||||
|
{
|
||||||
|
char value;
|
||||||
|
|
||||||
|
if (nb == -2147483648)
|
||||||
|
{
|
||||||
|
write(1, "-2147483648", 11);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (nb < 0)
|
||||||
|
{
|
||||||
|
write(1, "-", 1);
|
||||||
|
nb = -nb;
|
||||||
|
}
|
||||||
|
if (nb > 9)
|
||||||
|
{
|
||||||
|
ft_putnbr(nb / 10);
|
||||||
|
}
|
||||||
|
value = nb % 10 + '0';
|
||||||
|
write(1, &value, 1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void ft_sort_int_tab(int *tab, int size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int temp;
|
||||||
|
int changed;
|
||||||
|
|
||||||
|
changed = 1;
|
||||||
|
while (changed)
|
||||||
|
{
|
||||||
|
changed = 0;
|
||||||
|
i = 0;
|
||||||
|
while (i < size -1)
|
||||||
|
{
|
||||||
|
if (tab[i] > tab[i + 1])
|
||||||
|
{
|
||||||
|
temp = tab[i];
|
||||||
|
tab[i] = tab[i + 1];
|
||||||
|
tab[i + 1] = temp;
|
||||||
|
changed = 1;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main(void)
|
||||||
|
{
|
||||||
|
int tab[] = {5, 1, 4, 2, 8, 9, 3, 7, 6};
|
||||||
|
int size = 9;
|
||||||
|
|
||||||
|
ft_sort_int_tab(tab, size);
|
||||||
|
ft_putnbr(tab[0]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[1]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[2]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[3]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[4]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[5]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[6]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[7]);
|
||||||
|
write(1, ", ", 2);
|
||||||
|
ft_putnbr(tab[8]);
|
||||||
|
write(1, "\n ", 1);
|
||||||
|
return (0);
|
||||||
|
}*/
|
||||||
Reference in New Issue
Block a user