Previous Next Up Index Contents

Exercice 10.43

#include <stdio.h>

main()
{
 /* Prototypes des fonctions appelées */
 void MULTI_2_MATRICES (int *MAT1, int *MAT2, int *MAT3, 
                        int N, int M, int P, int CMAX);
 void LIRE_DIM     (int *L, int LMAX, int *C, int CMAX);
 void LIRE_MATRICE   (int *MAT, int L, int C, int CMAX);
 void ECRIRE_MATRICE (int *MAT, int L, int C, int CMAX);
 /* Variables locales */
 /* Les matrices et leurs dimensions */
 int M1[30][30], M2[30][30], M3[30][30];
 int N, M, P;
 int DUMMY; /* pour la lecture de la première dimension de */
            /* MAT2 à l'aide de LIRE_DIM. */
 
 /* Traitements */
 printf("*** Matrice 1 ***\n");
 LIRE_DIM (&N,30,&M,30);
  LIRE_MATRICE ((int*)M1,N,M,30 );
 printf("*** Matrice 2 ***\n");
 LIRE_DIM (&DUMMY,30,&P,30);
  LIRE_MATRICE ((int*)M2,M,P,30 );
 printf("Matrice donnée 1 : \n");
 ECRIRE_MATRICE ((int*)M1,N,M,30);
 printf("Matrice donnée 2 : \n");
 ECRIRE_MATRICE ((int*)M2,M,P,30);
 MULTI_2_MATRICES ((int*)M1 , (int*)M2 , (int*)M3 , N,M,P,30);
  printf("Matrice résultat : \n");
 ECRIRE_MATRICE ((int*)M3,N,P,30);
 return 0;
}

void MULTI_2_MATRICES (int *MAT1, int *MAT2, int *MAT3, 
                       int N, int M, int P, int CMAX)
{
  /* Variables locales */
 int I,J,K;
 /* Multiplier MAT1 et MAT2 en affectant le résultat à MAT3 */
 for (I=0; I<N; I++)
    for (J=0; J<P; J++)
       {
        *(MAT3+I*CMAX+J)=0;
        for (K=0; K<M; K++)
             *(MAT3+I*CMAX+J) += *(MAT1+I*CMAX+K) * *(MAT2+K*CMAX+J);
       }
}
 
void LIRE_DIM (int *L, int LMAX, int *C, int CMAX)
{
 . . .
}

void LIRE_MATRICE (int *MAT, int L, int C, int CMAX)
{
 . . .
}

void ECRIRE_MATRICE (int *MAT, int L, int C, int CMAX)
{
 . . .
}


Previous Next Up Index Contents

Feedback - Copyright © 1993,1996,1997 F.Faber