Multiplication matrcie

juju0612 Messages postés 19 Date d'inscription dimanche 17 février 2008 Statut Membre Dernière intervention 24 août 2008 - 9 mars 2008 à 12:34
vinc1008881 Messages postés 257 Date d'inscription dimanche 22 août 2004 Statut Membre Dernière intervention 29 septembre 2010 - 9 mars 2008 à 13:27
voila mon programme en faite je veux multiplier deux matrice d'absice et d'ordonnée mis par l'utilisateur
mais avec ma formule tout faite je ne sais pas que des matrices de (2,2)
comment estce que je pourrez faire pour n'importe quel dimension la multiplication(en gras)
merci d'avance
code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>


void main()
{
  int matA[10][10],i,j,matB[10][10],resul[10][10],x=0,y=0;


  printf("absice");
  scanf("%d",&x);
  printf("coordonée");
  scanf("%d",&y);
srand(time(NULL));


  for(i=0;i<x;i++)
  { for(j=0;j<y;j++)
   {
    matA[i][j]=rand()%10;
    scanf("%d\n",matA[i][j]);
  }
   }


     for(i=0;i<x;i++)
  { for(j=0;j<y;j++)
   {
    matB[i][j]=rand()%10;
    scanf("%d\n",matB[i][j]);
 }
  }




  for(i=0;i<x;i++)
  {printf("\n");
  for(j=0;j<y;j++)
   {printf("\t%d",matA[i][j]);
   }
  }
printf("\n              *\n");




   for(i=0;i<x;i++)
  {  printf("\n");
  for(j=0;j<y;j++)
   {printf("\t%d",matB[i][j]);
  }
   }


printf("\n         ===============\n");


 for(i=0;i<x;i++)
  {printf("\n");
   for(j=0;j<y;j++)
    {resul[0][0]=matA[0][0]*matB[0][0]+matA[0][1]*matB[1][0];
       resul[1][0]=matA[1][0]*matB[0][0]+matA[1][1]*matB[1][0];
       resul[0][1]=matA[0][0]*matB[0][1]+matA[0][1]*matB[1][1];
       resul[1][1]=matA[1][0]*matB[1][1]+matA[1][1]*matB[1][1];
      printf("\t%d",resul[i][j]);
    }
  }


 




getch();
}

1 réponse

vinc1008881 Messages postés 257 Date d'inscription dimanche 22 août 2004 Statut Membre Dernière intervention 29 septembre 2010 3
9 mars 2008 à 13:27
par definition : resul[i][j] = sigma (k=0...dimension_cummune, matA[i][k]*matB[k][j] )

int coef_croisee (int ** MatA, int **MatB, int i, int j, int dim_commune){

int tmp=0, k=0;

while(k<dim_commune){
tmp+=MatA[i][k]*MatB[k][j]:
}

return tmp;

}

//il faut executer cette fonction pour chaque couple (i,j), soit i*j fois pour obtenir la mantrice finale
0
Rejoignez-nous