From 01e37c19e6756f7039b1acfd9e47ae69e9cb8fb8 Mon Sep 17 00:00:00 2001 From: "dario.genga" <dario.genga@etu.hesge.ch> Date: Tue, 25 Jan 2022 13:15:24 +0100 Subject: [PATCH] Add ex1 --- ex1/ex1.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ex1/ex1.c b/ex1/ex1.c index ad790f3..1ee902f 100644 --- a/ex1/ex1.c +++ b/ex1/ex1.c @@ -9,5 +9,30 @@ #include <stdbool.h> int main() { + const int ARRAY_LENGTH = 8; + int *array = malloc(sizeof(int) * ARRAY_LENGTH); + int drop_count = 0; + int drop_total_value = 0; + + // Get the values + for (int i = 0; i < ARRAY_LENGTH; i++) { + int value; + scanf("%d", &value); + array[i] = value; + } + + // Parse the values + for (int i = 1; i < ARRAY_LENGTH; i++) { + if (array[i] < array[i - 1]) { + drop_count++; + drop_total_value += array[i - 1] - array[i]; + } + } + + // Display the results + printf("%d %d\n", drop_count, drop_total_value); + + // Free the memory and exit the program + free(array); return EXIT_SUCCESS; } -- GitLab