mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 13:17:16 +01:00
Piscine42
This commit is contained in:
32
C05/ex00/ft_iterative_factorial.c
Executable file
32
C05/ex00/ft_iterative_factorial.c
Executable 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);
|
||||
}
|
||||
20
C05/ex01/ft_recursive_factorial.c
Executable file
20
C05/ex01/ft_recursive_factorial.c
Executable 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
36
C05/ex02/ft_iterative_power.c
Executable 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
25
C05/ex03/ft_recursive_power.c
Executable 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
20
C05/ex04/ft_fibonacci.c
Executable 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
35
C05/ex05/ft_sqrt.c
Executable 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
30
C05/ex06/ft_is_prime.c
Executable 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
BIN
C05/fr.subject.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user