Exercice 10.39
#include <stdio.h>
main()
{
/* Prototypes des fonctions appelées */
long SOMME_MATRICE (int *MAT, int L, int C, 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 */
int M[30][30]; /* Matrice d'entiers */
int L, C; /* Dimensions de la matrice */
/* Traitements */
LIRE_DIM (&L, 30, &C, 30);
LIRE_MATRICE ( (int*)M, L,C,30);
printf("Matrice donnée : \n");
ECRIRE_MATRICE ( (int*)M, L,C,30);
printf("Somme des éléments de la matrice : %ld\n",
SOMME_MATRICE( (int*)M, L,C,30));
return 0;
}
long SOMME_MATRICE(int *MAT, int L, int C, int CMAX)
{
/* Variables locales */
int I,J;
long SOMME = 0;
/* Calcul de la somme */
for (I=0; I<L; I++)
for (J=0; J<C; J++)
SOMME += *(MAT + I*CMAX + J);
return SOMME;
}
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)
{
. . .
}
Feedback - Copyright © 1993,1996,1997 F.Faber