1
0

first commit

This commit is contained in:
KeyZox
2023-08-06 20:12:38 +02:00
parent 1fe062c970
commit eb6b113e51
125 changed files with 2987 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/27 11:34:45 by ajoly #+# #+# */
/* Updated: 2022/07/27 11:34:47 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_factorial(int nb)
{
int i;
int result;
i = 1;
result = 1;
if (nb < 0)
return (0);
if (nb == 0 || nb == 1)
return (1);
while (i <= nb)
{
result = i * result;
i++;
}
return (result);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/27 14:51:29 by ajoly #+# #+# */
/* Updated: 2022/08/01 13:39:06 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
if (nb < 0)
return (0);
if (nb == 1 || nb == 0)
return (1);
return (nb * ft_recursive_factorial(nb - 1));
}

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/27 16:42:03 by ajoly #+# #+# */
/* Updated: 2022/07/27 16:42:04 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int i;
i = 1;
if (power < 0)
return (0);
else if (power == 0)
return (1);
while (power > 0)
{
i = i * nb;
power--;
}
return (i);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/27 18:32:22 by ajoly #+# #+# */
/* Updated: 2022/07/27 18:51:35 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_power(int nb, int power)
{
if (power < 0)
return (0);
else if (power == 0)
return (1);
return (nb * ft_recursive_power(nb, power - 1));
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fibonacci.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/27 18:51:47 by ajoly #+# #+# */
/* Updated: 2022/07/27 18:51:48 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_fibonacci(int index)
{
if (index < 0)
return (-1);
if (index == 0)
return (0);
if (index == 1)
return (1);
return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2));
}

29
ended/C05/ex05/ft_sqrt.c Normal file
View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/27 21:41:03 by ajoly #+# #+# */
/* Updated: 2022/08/01 15:57:14 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_sqrt(int nb)
{
int i;
i = 1;
while (i * i < nb && i <= nb / 2)
i++;
if ((nb % i) == 0)
return (i);
return (0);
}
#include <stdio.h>
int main()
{
printf("%d", ft_sqrt(__INT_MAX__));
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/28 10:27:29 by ajoly #+# #+# */
/* Updated: 2022/08/01 15:58:00 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
if (nb <= 1)
return (0);
while (i <= nb / i)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_find_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/29 10:45:00 by ajoly #+# #+# */
/* Updated: 2022/08/01 15:57:50 by ajoly ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
if (nb <= 1)
return (0);
while (i <= nb / i)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}
int ft_find_next_prime(int nb)
{
int i;
i = nb;
while (ft_is_prime(i) != 1)
{
i++;
}
return (i);
}