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

Add ex2

Still missing some tests to determine if it's a latin square.
parent 59f43730
No related branches found
No related tags found
No related merge requests found
/* 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;
}
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