1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
void Affiche_Mat( float **A, int N, int M );
void zeros( float **Matrice, int N, int M );
float** Allocate_Mat_Memory(int N, int M);
void Free_Mat_Memory( float **A, int N );
int main()
{
float **M0;
int N,M;
// matrice zeros
M0 = Allocate_Mat_Memory( N, M );
printf("Entrez le nombre de lignes de la matrice N=");
scanf("%d",&N);
printf("Entrez le nombre de colonnes de la matrice M=");
scanf("%d",&M);
zeros(M0, N, M );
printf("La Matrice M0 est:\n\n");
Affiche_Mat( M0, N, M );
Free_Mat_Memory( M0, N );
}
float** Allocate_Mat_Memory(int N, int M)//Cette fonction permet d'allouer de la memoire pour une matrice qulquonque
{
int i;
float **A = NULL;
// On fait l'allocation de memoire pour un vecteur de N cases, C'est un vecteur de pointeurs
A = (float**) malloc( sizeof(float*) * N );
// Si l'allocation à réussi, On fait une allocation de M cases pour chaque ligne
if( A != NULL )
for( i=0; i<N; i++ )
A[i] = (float*) malloc( sizeof(float) * M );
return A;
}
void Free_Mat_Memory( float **A, int N )//cette fonction fait la désallocation d'une matrice (liberer la memoire)
{
int i;
// libérer chaque ligne
for( i=0; i<N; i++ )
free( A[i] );
free( A );
}
void Affiche_Mat( float **A, int N, int M )// Affichage des éléments de la matrice
{
int i, j;
for(i=0; i<N; i++)
{
for(j=0; j<M; j++)
printf("%f\t", A[i][j]);
printf("\n");
}
}
void zeros(float **Matrice, int N, int M )//matrice rempli avec des 0
{
int i, j;
for( i=0; i<N; i++ )
for( j=0; j<M; j++ )
{
Matrice[i][j]=0;
}
} |
Partager