salut!
Je suis en plein TD sur les matrices, on a géré la base (saisie de matrice, désallocation, matrice unité, affichage d'une matrice), mais là je bloque sur une fonction où je dois effectuer la transposée d'une matrice(m,n) (inversement ligne / colonne).
Voilà mon code source :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 float ** rempmat(int Nbl,int nbc) { float ** tab; int i,j; float nbre,tmp ; /*Initialisation matrice*/ tab = (float**)malloc(Nbl*sizeof(float*)); for (i=0;i<Nbl;i++) { *(tab+i) = (float*)malloc(nbc*sizeof(float)); for (j=0;j<nbc;j++) { *(*(tab+i)+j)=0; } } /*Saisie d'une matrice par l'utilisateur*/ for (i=0;i<Nbl;i++) { *(tab+i) = (float*)malloc(nbc*sizeof(float)); for (j=0;j<nbc;j++) { printf("saisir nombre reel \n") ; scanf("%f",&nbre) ; *(*(tab+i)+j)=nbre ; } } /*Transposée matrice*/ for (i=0;i<Nbl;i++) { *(tab+i) = (float*)malloc(nbc*sizeof(float)); for (j=0;j<nbc;j++) { tmp=*(*(tab+i)+j) *(*(tab+i)+j) = *(*(tab+j)+i) ; *(*(tab+j)+i) = tmp; } } return tab ; }
Je dois gérer le cas de toutes les matrices, pas seulement des matrices carrées, mais même pour ces dernières ca ne fonctionne pas.
Si quelqu'un a une idée...![]()
Partager