Skip to content
Snippets Groups Projects
Commit 01e37c19 authored by dario.genga's avatar dario.genga
Browse files

Add ex1

parent 1760db67
No related branches found
No related tags found
No related merge requests found
...@@ -9,5 +9,30 @@ ...@@ -9,5 +9,30 @@
#include <stdbool.h> #include <stdbool.h>
int main() { 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; return EXIT_SUCCESS;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment