#include <stdio.h>
#include <stdlib.h>
void menu();
char choix_menu();
void saisie_taille(int taille[2]);
void saisie (int matrice[10][10],int taille[2]);
void affichage_matrice(int matrice[10][10], int taille[2]);
void affichage(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2]);
void multiplication_matricielle(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2]);
int main()
{
menu();
return 0;
}
void saisie (int matrice[10][10],int taille[2])
{
int i,j;
saisie_taille(taille);
for (i=0;i<= taille[0]-1;i++)
{
for (j=0;j<=taille[1]-1;j++)
{
printf("la valeur de ligne %d, colonne %d: ", i+1,j+1);
scanf("%d",&matrice[i][j]);
getchar();
}
}
}
void menu()
{
int matrice1[10][10];
int matrice2[10][10];
int matrice3[10][10];
int taille1[2] = {0,0};
int taille2[2] = {0,0};
char choix = 'a';
do
{
affichage(matrice1, matrice2, taille1, taille2);
choix = choix_menu();
if (choix == 'a')
{
saisie(matrice1, taille1);
}
if (choix == 'b')
{
saisie(matrice2, taille2);
}
if (choix == 'c')
{
multiplication_matricielle(matrice1, matrice2, taille1, taille2);
}
if (choix == 'd')
{
multiplication_matricielle(matrice2, matrice1, taille2, taille1);
}
}while(choix != 'q');
}
void affichage(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2])
{
printf("\nMENU MULTIPLICATION DE MATRICE\n");
printf("Matrice 1:\n");
affichage_matrice(matrice1,taille1);
printf("Matrice 2:\n");
affichage_matrice(matrice2,taille2);
printf("a. Remplir matrice 1. \n");
printf("b. Remplir matrice 2. \n");
printf("c. Multiplier matrice 1 par matrice 2.\n");
printf("d. Multiplier matrice 2 par matrice 1.\n");
printf("q. Quitter.\n");
}
void affichage_matrice(int matrice[10][10], int taille[2])
{
int i,j;
for (i=0;i<= taille[0]-1;i++)
{
for (j=0;j<=taille[1]-1;j++)
{
printf("%d ",matrice[i][j]);
}
printf("\n");
}
}
char choix_menu()
{
char choix;
do
{
printf("votre choix?\n");
scanf("%c",&choix);
getchar();
if (choix == 'a' || choix =='b' || choix =='c' || choix == 'd' ||choix =='q')
{
return choix;
}
}while(1);
}
void saisie_taille(int taille[2])
{
printf("nombre de ligne: \n");
scanf("%d", &taille[0]);
getchar();
printf("\nnombre de ligne: \n");
scanf("%d", &taille[1]);
getchar();
printf("\n");
}
void multiplication_matricielle(int matrice1[10][10], int matrice2[10][10], int taille1[2], int taille2[2])
{
int i,j,k;
int matrice[10][10];
int taille3[2];
taille3[0]=taille1[0];
taille3[1]=taille2[1];
if (taille1[1] != taille2[0])
{
printf("multiplication de matrice impossible\n");
}
else
{
for (i=0;i<= taille3[0]-1;i++)
{
for (j=0;j<=taille3[1]-1;j++)
{
matrice[i][j] = 0;
for (k=0; k<= taille1[1]-1; k++)
{
matrice[i][j] = matrice[i][j] + matrice1[i][k] * matrice2[k][j];
}
}
}
printf("Le produit matriciel donne: \n");
affichage_matrice(matrice, taille3);
printf("Appuyer sur entrer pour revenir au menu!\n");
getchar();
printf("\n");
}
}