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 71 72 73 74 75 76 77 78
| #include <stdio.h>
#include <stdlib.h>
#include <conio.h>
/* définition de la structure */
typedef struct mat
{ int nbl; /* nombre de lignes */
int nbc; /* nombre de colonnes */
float **t; /* les éléments */ } matrice;
/* la fonction permettant la lecture */
matrice lecture()
{
matrice *m;
printf("entrez le nombre de lignes de votre matrice");
scanf("%d",m.nbl);
printf("entrez le nombre de colonnes de votre matrice");
scanf("%d",m.nbc);
for (int i=0;i<m.nbl;i++)
{(t+i)=(float*) malloc (nbc * sizeof(float));}
for (i=0;i<(*m).nbl;i++)
{
for (j=0;j<(*m).nbc;j++)
{ printf("donner l'element %d de la ligne %d",i,j);
scanf("%lf",m.((t+i)+j));
}}
return (m);
}
/* la fonction permettant l'affichage */
void affichage( matrice m)
{
int i,j;
for(i=0; i< m.nbl ; i++)
{
for (j=0 ; j<m.nbc ; j++)
{ printf("%f",m.(**((t+i)+j))); }
}
}
/* la fonction permettant d'obtenir le transposé d'une matrice */
matrice transpose (matrice m)
{ int i,j;
matrice *tr;
tr=(matrice*)malloc(sizeof(m));
(*tr).nbl = m.nbc;
(*tr).nbc = m.nbl;
for (i=0 ; i<(*tr).nbl ; i++)
{
for (j=0 ; j<(*tr).nbc ; j++)
{
(*tr).(*((t+i)+j)) = M.(*((t+i)+j)) ;
}}
return(*tr);
}
void main()
{
matrice m,a;
m=lecture();
a=transpose(m);
affichage(a);
getch();
} |
Partager