efrei/programmation-c-cpp/tp3/addition-matricielle.c

39 lines
910 B
C
Raw Normal View History

2021-11-02 14:46:30 +01:00
/* Addition matricielle */
#include <stdio.h>
#include <stdlib.h>
#define COLONNES 2
#define LIGNES 3
int main() {
int matrice_gauche[LIGNES][COLONNES];
int matrice_droite[LIGNES][COLONNES];
int matrice_addition[LIGNES][COLONNES];
matrice_gauche[0][0] = 1;
matrice_gauche[0][1] = 3;
matrice_gauche[1][0] = 1;
matrice_gauche[1][1] = 0;
matrice_gauche[2][0] = 1;
matrice_gauche[2][1] = 2;
matrice_droite[0][0] = 0;
matrice_droite[0][1] = 0;
matrice_droite[1][0] = 7;
matrice_droite[1][1] = 5;
matrice_droite[2][0] = 2;
matrice_droite[2][1] = 1;
for (int lgn = 0; lgn < LIGNES; lgn++) {
for (int col = 0; col < COLONNES; col++) {
matrice_addition[lgn][col] = matrice_gauche[lgn][col] + matrice_droite[lgn][col];
printf("%d ", matrice_addition[lgn][col]);
}
printf("\n");
}
return 0;
}