From 59f43730653f76a23bccbde218573c408094eda3 Mon Sep 17 00:00:00 2001 From: "dario.genga" <dario.genga@etu.hesge.ch> Date: Tue, 7 Dec 2021 14:50:00 +0100 Subject: [PATCH] Add non finished ex3 --- ex1/main.c | 2 +- ex3/main.c | 41 +++++++++++++++++++++++++++++++++++++++++ ex3/makefile | 10 ++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 ex3/main.c create mode 100644 ex3/makefile diff --git a/ex1/main.c b/ex1/main.c index cd15dcf..9a1d530 100644 --- a/ex1/main.c +++ b/ex1/main.c @@ -32,7 +32,7 @@ int main() { } } // Print the result and free the memory - printf("\ndistance : %d\n", distance); + printf("\ndistance: %d\n", distance); free(word1); free(word2); diff --git a/ex3/main.c b/ex3/main.c new file mode 100644 index 0000000..153989f --- /dev/null +++ b/ex3/main.c @@ -0,0 +1,41 @@ +/* Author : Dario GENGA + * Date : 07.12.2021 + * Description : ContrĂ´le continue 1 - Exercice 3 + */ + +#include <stdio.h> +#include <stdlib.h> +#define ARRAY_SIZE 3 + +int main() { + int value = 0; + int result = 0; + int money[ARRAY_SIZE] = {10, 2, 1}; + scanf("%d", &value); + + for (int i = 0; i < ARRAY_SIZE; i++) { + int sub_index = i; + int rest = value; + int quotient = value / money[i]; + + if (quotient > 0) { + for (int k = 1; k <= quotient; k++) { + while (rest != 0 && sub_index < ARRAY_SIZE) { + int current_money = k * money[sub_index]; + rest = rest % current_money; + sub_index++; + } + + if (rest == 0) { + result++; + rest = value; + sub_index = i; + } + } + } + } + + printf("\n%d\n", result); + + return EXIT_SUCCESS; +} diff --git a/ex3/makefile b/ex3/makefile new file mode 100644 index 0000000..a217aa2 --- /dev/null +++ b/ex3/makefile @@ -0,0 +1,10 @@ +LIB=-lm +CC=gcc -Wall -Wextra -pedantic -g + +main: main.o + $(CC) $^ -fsanitize=address -fsanitize=leak -o $@ $(LIB) + +main.o: main.c + $(CC) -c $< $(LIB) +clean: + rm -f *.o main \ No newline at end of file -- GitLab