diff --git a/ex2/main.c b/ex2/main.c new file mode 100644 index 0000000000000000000000000000000000000000..c30a2fc71a3e9563a1526c794e347a3da30f6845 --- /dev/null +++ b/ex2/main.c @@ -0,0 +1,56 @@ +/* Author : Dario GENGA + * Date : 07.12.2021 + * Description : Contrôle continue 1 - Exercice 2 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#define NB_ROW_AND_COL 4 + +int main() { + bool is_normalized = true; + char *normalized = "oui"; + char *not_normalized = "non"; + int (*square)[NB_ROW_AND_COL] = malloc(NB_ROW_AND_COL * sizeof(*square)); + + // i = row index, k = col index + for (int i = 0; i < NB_ROW_AND_COL; i++) { + for (int k = 0; k < NB_ROW_AND_COL; k++) { + int value; + scanf("%d", &value); + square[i][k] = value; + + if (value <= 0 || value > NB_ROW_AND_COL) { + is_normalized = false; + } + } + } + + // Verify if the square is normalized + int prev = square[0][0]; + for (int i = 1; i < NB_ROW_AND_COL; i++) { + if (prev > square[i][0]) { + is_normalized = false; + break; + } + } + prev = square[0][0]; + for (int k = 1; k < NB_ROW_AND_COL; k++) { + if (prev > square[0][k]) { + is_normalized = false; + break; + } + } + + // Print the result and free the memory + if (is_normalized) { + printf("\nlatin normalisé : %s\n", normalized); + } else { + printf("\nlatin normalisé : %s\n", not_normalized); + } + + free(square); + + return EXIT_SUCCESS; +} diff --git a/ex2/makefile b/ex2/makefile new file mode 100644 index 0000000000000000000000000000000000000000..a217aa28ef6b3524ffcef99d4b31e2d03e8b0cc4 --- /dev/null +++ b/ex2/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