init
This commit is contained in:
26
C/c05/ex00/ft_iterative_factorial.c
Normal file
26
C/c05/ex00/ft_iterative_factorial.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_iterative_factorial.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 17:18:33 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 17:28:28 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_iterative_factoriel(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);
|
||||
}
|
21
C/c05/ex01/ft_recursive_factorial.c
Normal file
21
C/c05/ex01/ft_recursive_factorial.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_recursive_factorial.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 17:06:51 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 17:29:21 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_recursive_factoriel(int nb)
|
||||
{
|
||||
if (nb < 0)
|
||||
return (0);
|
||||
if (nb == 1)
|
||||
return (nb);
|
||||
else
|
||||
return (nb * ft_recursive_factoriel(nb - 1));
|
||||
}
|
25
C/c05/ex02/ft_iterative_power.c
Normal file
25
C/c05/ex02/ft_iterative_power.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_iterative_power.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 17:17:04 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 17:29:47 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);
|
||||
}
|
18
C/c05/ex03/ft_recursive_power.c
Normal file
18
C/c05/ex03/ft_recursive_power.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_recursive_power.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/19 17:28:20 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 17:30:19 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_recursive_power(int nb, int power)
|
||||
{
|
||||
if (power <= 0)
|
||||
return (1);
|
||||
return (ft_recursive_power(nb, power - 1) * nb);
|
||||
}
|
22
C/c05/ex04/ft_fibonacci.c
Normal file
22
C/c05/ex04/ft_fibonacci.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_fibonacci.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/20 10:23:01 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 17:30:54 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));
|
||||
}
|
25
C/c05/ex05/ft_sqrt.c
Normal file
25
C/c05/ex05/ft_sqrt.c
Normal 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);
|
||||
}
|
30
C/c05/ex06/ft_is_prime.c
Normal file
30
C/c05/ex06/ft_is_prime.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_is_prime.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/20 13:40:46 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 17:38:33 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_prime(int nb)
|
||||
{
|
||||
int i;
|
||||
long int nbr_out;
|
||||
|
||||
if (nb < 0)
|
||||
nbr_out = (long int) -nb;
|
||||
else
|
||||
nbr_out = (long int) nb;
|
||||
i = 2;
|
||||
while (i <= nbr_out / i)
|
||||
{
|
||||
if (nbr_out % i == 0)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
40
C/c05/ex07/ft_find_next_prime.c
Normal file
40
C/c05/ex07/ft_find_next_prime.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_find_next_prime.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/20 14:31:43 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/25 17:37:57 by cchauvet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_is_prime(int nb)
|
||||
{
|
||||
int i;
|
||||
long int nbr_out;
|
||||
|
||||
if (nb < 0)
|
||||
nbr_out = (long int) -nb;
|
||||
else
|
||||
nbr_out = (long int) nb;
|
||||
i = 2;
|
||||
while (i <= nbr_out / i)
|
||||
{
|
||||
if (nbr_out % i == 0)
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_find_next_prime(int nb)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = nb;
|
||||
while (ft_is_prime(i) == 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
Reference in New Issue
Block a user