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

Add non finished ex3

parent 7adcfe42
Branches
Tags 3.1.1
No related merge requests found
...@@ -32,7 +32,7 @@ int main() { ...@@ -32,7 +32,7 @@ int main() {
} }
} }
// Print the result and free the memory // Print the result and free the memory
printf("\ndistance : %d\n", distance); printf("\ndistance: %d\n", distance);
free(word1); free(word1);
free(word2); free(word2);
......
/* 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;
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment