From 6e576f39cae125ccf30f802332fdaf94f7c362fc Mon Sep 17 00:00:00 2001 From: Guy Baconniere Date: Tue, 17 Aug 2021 18:28:27 +0200 Subject: [PATCH] sync --- C_Piscine_C_05/Makefile | 23 +++++++++++++ .../git/ex00/ft_iterative_factorial.c | 23 +++++++++++++ C_Piscine_C_05/git/ex00/main.c | 30 +++++++++++++++++ C_Piscine_C_05/git/ex00/main.sh | 8 +++++ .../git/ex01/ft_recursive_factorial.c | 22 +++++++++++++ C_Piscine_C_05/git/ex01/main.c | 30 +++++++++++++++++ C_Piscine_C_05/git/ex01/main.sh | 8 +++++ C_Piscine_C_05/git/ex02/ft_iterative_power.c | 14 ++++++++ C_Piscine_C_05/git/ex02/main.c | 33 +++++++++++++++++++ C_Piscine_C_05/git/ex02/main.sh | 8 +++++ C_Piscine_C_05/git/ex03/ft_recursive_power.c | 22 +++++++++++++ C_Piscine_C_05/git/ex03/main.c | 33 +++++++++++++++++++ C_Piscine_C_05/git/ex03/main.sh | 8 +++++ C_Piscine_C_05/git/ex04/ft_fibonacci.c | 29 ++++++++++++++++ C_Piscine_C_05/git/ex04/main.c | 30 +++++++++++++++++ C_Piscine_C_05/git/ex04/main.sh | 8 +++++ 16 files changed, 329 insertions(+) create mode 100644 C_Piscine_C_05/Makefile create mode 100644 C_Piscine_C_05/git/ex00/ft_iterative_factorial.c create mode 100644 C_Piscine_C_05/git/ex00/main.c create mode 100755 C_Piscine_C_05/git/ex00/main.sh create mode 100644 C_Piscine_C_05/git/ex01/ft_recursive_factorial.c create mode 100644 C_Piscine_C_05/git/ex01/main.c create mode 100755 C_Piscine_C_05/git/ex01/main.sh create mode 100644 C_Piscine_C_05/git/ex02/ft_iterative_power.c create mode 100644 C_Piscine_C_05/git/ex02/main.c create mode 100755 C_Piscine_C_05/git/ex02/main.sh create mode 100644 C_Piscine_C_05/git/ex03/ft_recursive_power.c create mode 100644 C_Piscine_C_05/git/ex03/main.c create mode 100755 C_Piscine_C_05/git/ex03/main.sh create mode 100644 C_Piscine_C_05/git/ex04/ft_fibonacci.c create mode 100644 C_Piscine_C_05/git/ex04/main.c create mode 100755 C_Piscine_C_05/git/ex04/main.sh diff --git a/C_Piscine_C_05/Makefile b/C_Piscine_C_05/Makefile new file mode 100644 index 0000000..13863f8 --- /dev/null +++ b/C_Piscine_C_05/Makefile @@ -0,0 +1,23 @@ + +# +# Copyright (c) 2021 Guy Baconniere. +# +## How to use this Makefile +# +# cd git +# mkdir ex00 +# cd ex00 +# make -f ../../Makefile ex00 +# + +clone: + @git clone git@vogsphere.42lausanne.ch:vogsphere/intra-uuid-157e39ca-a99c-4439-9939-72b0b56b975c-3725547 git + +cc: + @norminette -R CheckForbiddenSourceHeader + @gcc -Wall -Wextra -Werror -o a.out *.c + @./a.out + @rm -f a.out + +all: clone + diff --git a/C_Piscine_C_05/git/ex00/ft_iterative_factorial.c b/C_Piscine_C_05/git/ex00/ft_iterative_factorial.c new file mode 100644 index 0000000..e06ea34 --- /dev/null +++ b/C_Piscine_C_05/git/ex00/ft_iterative_factorial.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 15:50:19 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 15:50:21 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_iterative_factorial(int nb) +{ + int n; + int i; + + n = 1; + i = 1; + while (i <= nb) + n *= i++; + return (n); +} diff --git a/C_Piscine_C_05/git/ex00/main.c b/C_Piscine_C_05/git/ex00/main.c new file mode 100644 index 0000000..0a6d1f1 --- /dev/null +++ b/C_Piscine_C_05/git/ex00/main.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 15:19:55 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 15:25:37 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +int ft_iterative_factorial(int nb); + +int main(void) +{ + int nb; + int result; + + printf("Input Number: "); + scanf("%d", &nb); + result = ft_iterative_factorial(nb); + printf("nb=%d result=%d (ft_iterative_factorial)\n", nb, result); + return (0); +} diff --git a/C_Piscine_C_05/git/ex00/main.sh b/C_Piscine_C_05/git/ex00/main.sh new file mode 100755 index 0000000..292faee --- /dev/null +++ b/C_Piscine_C_05/git/ex00/main.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +#norminette -R CheckForbiddenSourceHeader ft_*.c +norminette -R CheckForbiddenSourceHeader +gcc -Wall -Wextra -Werror -o a.out *.c +echo $(basename $PWD): +./a.out +rm -f a.out diff --git a/C_Piscine_C_05/git/ex01/ft_recursive_factorial.c b/C_Piscine_C_05/git/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..3428264 --- /dev/null +++ b/C_Piscine_C_05/git/ex01/ft_recursive_factorial.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 15:34:34 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 15:50:00 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_factorial(int nb) +{ + if (nb > 0) + nb *= ft_recursive_factorial(nb - 1); + else if (nb == 0) + nb = 1; + else + nb = 0; + return (nb); +} diff --git a/C_Piscine_C_05/git/ex01/main.c b/C_Piscine_C_05/git/ex01/main.c new file mode 100644 index 0000000..2c9634b --- /dev/null +++ b/C_Piscine_C_05/git/ex01/main.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 15:34:45 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 15:35:27 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +int ft_recursive_factorial(int nb); + +int main(void) +{ + int nb; + int result; + + printf("Input Number: "); + scanf("%d", &nb); + result = ft_recursive_factorial(nb); + printf("nb=%d result=%d (ft_recursive_factorial)\n", nb, result); + return (0); +} diff --git a/C_Piscine_C_05/git/ex01/main.sh b/C_Piscine_C_05/git/ex01/main.sh new file mode 100755 index 0000000..292faee --- /dev/null +++ b/C_Piscine_C_05/git/ex01/main.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +#norminette -R CheckForbiddenSourceHeader ft_*.c +norminette -R CheckForbiddenSourceHeader +gcc -Wall -Wextra -Werror -o a.out *.c +echo $(basename $PWD): +./a.out +rm -f a.out diff --git a/C_Piscine_C_05/git/ex02/ft_iterative_power.c b/C_Piscine_C_05/git/ex02/ft_iterative_power.c new file mode 100644 index 0000000..89f349d --- /dev/null +++ b/C_Piscine_C_05/git/ex02/ft_iterative_power.c @@ -0,0 +1,14 @@ +int ft_iterative_power(int nb, int power) +{ + int n; + + if (power < 0) + n = 0; + else if (power == 0) + n = 1; + else + n = nb; + while (power > 0 && --power) + n *= nb; + return (n); +} diff --git a/C_Piscine_C_05/git/ex02/main.c b/C_Piscine_C_05/git/ex02/main.c new file mode 100644 index 0000000..b359261 --- /dev/null +++ b/C_Piscine_C_05/git/ex02/main.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 16:29:14 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 16:29:34 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +int ft_iterative_power(int nb, int power); + +int main(void) +{ + int nb; + int power; + int result; + + printf("Input Number: "); + scanf("%d", &nb); + printf("Input Power: "); + scanf("%d", &power); + result = ft_iterative_power(nb, power); + printf("nb=%d power=%d result=%d (ft_iterative_power)\n", nb, power, result); + return (0); +} diff --git a/C_Piscine_C_05/git/ex02/main.sh b/C_Piscine_C_05/git/ex02/main.sh new file mode 100755 index 0000000..292faee --- /dev/null +++ b/C_Piscine_C_05/git/ex02/main.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +#norminette -R CheckForbiddenSourceHeader ft_*.c +norminette -R CheckForbiddenSourceHeader +gcc -Wall -Wextra -Werror -o a.out *.c +echo $(basename $PWD): +./a.out +rm -f a.out diff --git a/C_Piscine_C_05/git/ex03/ft_recursive_power.c b/C_Piscine_C_05/git/ex03/ft_recursive_power.c new file mode 100644 index 0000000..352679e --- /dev/null +++ b/C_Piscine_C_05/git/ex03/ft_recursive_power.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 16:50:55 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 17:05:03 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_power(int nb, int power) +{ + if (power < 0) + nb = 0; + else if (power == 0) + nb = 1; + else + nb *= ft_recursive_power(nb, --power); + return (nb); +} diff --git a/C_Piscine_C_05/git/ex03/main.c b/C_Piscine_C_05/git/ex03/main.c new file mode 100644 index 0000000..bb4713b --- /dev/null +++ b/C_Piscine_C_05/git/ex03/main.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 16:49:41 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 16:59:46 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +int ft_recursive_power(int nb, int power); + +int main(void) +{ + int nb; + int power; + int result; + + printf("Input Number: "); + scanf("%d", &nb); + printf("Input Power: "); + scanf("%d", &power); + result = ft_recursive_power(nb, power); + printf("nb=%d power=%d result=%d (ft_recursive_power)\n", nb, power, result); + return (0); +} diff --git a/C_Piscine_C_05/git/ex03/main.sh b/C_Piscine_C_05/git/ex03/main.sh new file mode 100755 index 0000000..292faee --- /dev/null +++ b/C_Piscine_C_05/git/ex03/main.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +#norminette -R CheckForbiddenSourceHeader ft_*.c +norminette -R CheckForbiddenSourceHeader +gcc -Wall -Wextra -Werror -o a.out *.c +echo $(basename $PWD): +./a.out +rm -f a.out diff --git a/C_Piscine_C_05/git/ex04/ft_fibonacci.c b/C_Piscine_C_05/git/ex04/ft_fibonacci.c new file mode 100644 index 0000000..b80a0e5 --- /dev/null +++ b/C_Piscine_C_05/git/ex04/ft_fibonacci.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_fibonacci.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 17:09:01 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 18:28:10 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_fibonacci(int index) +{ + int nb; + int n1; + int n2; + + nb = -1; + n1 = 0; + n2 = 1; + if (index == 0) + nb = n1; + else if (index == 1) + nb = n2; + else if (index > 1) + nb = ft_fibonacci(index) + ft_fibonacci(index - 1); + return (nb); +} diff --git a/C_Piscine_C_05/git/ex04/main.c b/C_Piscine_C_05/git/ex04/main.c new file mode 100644 index 0000000..180fa94 --- /dev/null +++ b/C_Piscine_C_05/git/ex04/main.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2021/08/17 17:06:57 by gbaconni #+# #+# */ +/* Updated: 2021/08/17 17:12:01 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +int ft_fibonacci(int index); + +int main(void) +{ + int index; + int result; + + printf("Input Index: "); + scanf("%d", &index); + result = ft_fibonacci(index); + printf("index=%d result=%d (ft_fibonacci)\n", index, result); + return (0); +} diff --git a/C_Piscine_C_05/git/ex04/main.sh b/C_Piscine_C_05/git/ex04/main.sh new file mode 100755 index 0000000..292faee --- /dev/null +++ b/C_Piscine_C_05/git/ex04/main.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e +#norminette -R CheckForbiddenSourceHeader ft_*.c +norminette -R CheckForbiddenSourceHeader +gcc -Wall -Wextra -Werror -o a.out *.c +echo $(basename $PWD): +./a.out +rm -f a.out