diff --git a/TP1/E11.c b/TP1/E11.c new file mode 100644 index 0000000..251c93e --- /dev/null +++ b/TP1/E11.c @@ -0,0 +1,89 @@ +/* Opération sur des matrices */ +#include + + +int main() { + int M, N; + + printf("Entrez les dimensions en M des matrices : "); + scanf("%d", &M); + printf("Entrez les dimensions en N des matrices : "); + scanf("%d", &N); + + if (M < 1 || M > 50 || N < 1 || N > 50) { + printf("M et N doivent être compris entre 1 et 50\n"); + return 2; + } + + int A[50][50]; + int B[50][50]; + int m, n; + + for (n = 0; n < N; n++) { + for (m = 0; m < M; m++) { + printf("Entrez la valeur de la matrice A aux coordonnées (%d, %d) : ", m, n); + scanf("%d", &A[m][n]); + } + } + + for (n = 0; n < N; n++) { + for (m = 0; m < M; m++) { + printf("Entrez la valeur de la matrice B aux coordonnées (%d, %d) : ", m, n); + scanf("%d", &B[m][n]); + } + } + + int choix; + printf("Tapez 0 pour calculer A+B ; 1 pour calculer A×B : "); + scanf("%d", &choix); + + int T[50][50]; + + printf("\n"); + if (!choix) { + printf("A+B"); + for (n = 0; n < N; n++) { + for (m = 0; m < M; m++) { + T[m][n] = A[m][n] + B[m][n]; + } + } + } else { + int i, S; + if (M != N) { + printf("La largeur de A doit être égale à la hauteur de B"); + return 2; + + } + printf("A×B"); + for (n = 0; n < N; n++) { + for (m = 0; m < M; m++) { + S = 0; + for (i = 0; i < M; i++) { + S += A[i][n] * B[m][i]; + } + T[m][n] = S; + } + } + } + + for (m = 0; m < M; m++) { + printf("│"); + printf("%3d", m); + } + for (n = 0; n < N; n++) { + // Dessine une ligne + printf("\n───"); + for (m = 0; m < M; m++) { + printf("┼───"); + } + printf("\n"); + + printf("%3d", n); + for (m = 0; m < M; m++) { + printf("│"); + printf("%3d", T[m][n]); + } + } + printf("\n"); + return 0; +} diff --git a/TP1/Makefile b/TP1/Makefile index 149151e..aecc9bb 100644 --- a/TP1/Makefile +++ b/TP1/Makefile @@ -1,4 +1,4 @@ -all: $(subst c,exe,$(shell ls)) +all: $(subst c,exe,$(shell ls *.c)) E1-1.exe: E1-1.c gcc E1-1.c -o E1-1.exe @@ -35,6 +35,9 @@ E9.exe: E9.c E10.exe: E10.c gcc E10.c -o E10.exe + +E11.exe: E11.c + gcc E11.c -o E11.exe .PHONY: all clean