This commit is contained in:
Camille Chauvet
2023-05-17 16:45:25 +00:00
commit 29ed24d567
619 changed files with 16119 additions and 0 deletions

BIN
Correction/sam/ex00/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:18:33 by cchauvet #+# #+# */
/* Updated: 2022/08/01 14:51:30 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_factorial(int nb)
{
int nbr_out;
if (nb < 0)
return (0);
nbr_out = 1;
while (nb > 0)
{
nbr_out = nbr_out * nb;
nb--;
}
return (nbr_out);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc > 1)
printf("%d", ft_iterative_factorial(atoi(argv[1])));
}

BIN
Correction/sam/ex01/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:06:51 by cchauvet #+# #+# */
/* Updated: 2022/08/01 14:55:59 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
if (nb < 0)
return (0);
if (nb == 1)
return (nb);
else
return (nb * ft_recursive_factorial(nb - 1));
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc > 1)
printf("%d", ft_recursive_factorial(atoi(argv[1])));
}

BIN
Correction/sam/ex02/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:17:04 by cchauvet #+# #+# */
/* Updated: 2022/08/01 15:00:30 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int nbr_out;
if (power < 0)
return (0);
if (power == 0)
return (1);
nbr_out = nb;
while (--power > 0)
nbr_out = nbr_out * nb;
return (nbr_out);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc > 2)
printf("%d", ft_iterative_power(atoi(argv[1]), atoi(argv[2])));
}

BIN
Correction/sam/ex03/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:28:20 by cchauvet #+# #+# */
/* Updated: 2022/08/01 15:04:30 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_power(int nb, int power)
{
if (power < 0)
return (0);
if (power == 0)
return (1);
return (ft_recursive_power(nb, power - 1) * nb);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc > 2)
printf("%d", ft_recursive_power(atoi(argv[1]), atoi(argv[2])));
}

BIN
Correction/sam/ex04/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fibonacci.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 10:23:01 by cchauvet #+# #+# */
/* Updated: 2022/08/01 15:07:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_fibonacci(int index)
{
if (index == 0)
return (0);
if (index == 1)
return (1);
if (index < 0)
return (-1);
return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2));
}
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
if (argc > 1)
printf("%d", ft_fibonacci(atoi(argv[1])));
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/25 17:33:47 by cchauvet #+# #+# */
/* Updated: 2022/07/25 17:35:41 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_sqrt(int nb)
{
int i;
i = 1;
while (i <= nb / i)
{
if (i * i == nb)
return (i);
i++;
}
return (0);
}

BIN
Correction/sam/ex06/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 13:40:46 by cchauvet #+# #+# */
/* Updated: 2022/08/01 15:11:21 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
while (i <= nb / i)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc > 1)
printf("%d", ft_is_prime(atoi(argv[1])));
}

BIN
Correction/sam/ex07/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_find_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 14:31:43 by cchauvet #+# #+# */
/* Updated: 2022/08/01 15:13:17 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
while (i <= nb / i)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}
int ft_find_next_prime(int nb)
{
int i;
if (nb < 2)
return (2);
i = nb;
while (ft_is_prime(i) == 0)
i++;
return (i);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
if (argc > 1)
printf("%d", ft_find_next_prime(atoi(argv[1])));
}