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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <stdio.h>
#define LMAX 10
#define CMAX 10
void GetDim(int *FL, int *FC, int FLmax, int FCmax) ;
void GetMat(int *FMat, int *FL, int *FC) ;
void DisplayMat(int *FMat, int *FL, int *FC) ;
int TranspoMat(int *FMat, int *FL, int *FC) ;
int main(void)
{
int Mat[LMAX][CMAX] ;
int Lig, Col ;
int ok ;
Lig = 11 ;
Col = 11 ;
ok = 0 ;
GetDim(&Lig, &Col, LMAX, CMAX) ;
printf("\n\nSAISIE DE MATRICE : \n") ;
GetMat(*Mat, &Lig, &Col) ;
printf("\nAFFICHAGE MATRICE : \n") ;
DisplayMat( (int *)Mat, &Lig, &Col) ;
if ( TranspoMat(*Mat, &Lig, &Col) )
{
printf("\nAFFICHAGE TRANSPO : \n") ;
DisplayMat( (int *)Mat, &Lig, &Col) ;
}
else
printf("\nLa matrice ne peut etre transposee.") ;
printf("\n\n") ;
return 0 ;
}
void GetDim(int *FL, int *FC, int FLmax, int FCmax)
{
do
{
printf("\nEntrez le nbr de lignes : ") ;
scanf("%d", FL) ;
} while ( *FL < 0 || *FL > FLmax ) ;
do
{
printf("\nEntrez le nbr de colonnes : ") ;
scanf("%d", FC) ;
} while ( *FC < 0 || *FC > FCmax ) ;
}
void GetMat(int *FMat, int *FL, int *FC)
{
int i, j ;
for ( i = 0 ; i < *FL ; i++ )
for ( j = 0 ; j < *FC ; j++ )
{
printf("Element[%d][%d] : ", i, j) ;
scanf("%d", (int *) FMat + i * *FC + j ) ;
}
}
void DisplayMat(int *FMat, int *FL, int *FC)
{
int i, j ;
printf("\n") ;
for ( i = 0 ; i < *FL ; i++ )
{
for ( j = 0 ; j < *FC ; j++ )
printf("%d", *(FMat + i * *FC + j) ) ;
printf("\n") ;
}
}
int TranspoMat(int *FMat, int *FL, int *FC)
{
void PermutMat(int *x, int *y) ;
int i, j ;
int dmax ;
if ( *FL > CMAX || *FC > LMAX )
return 0 ;
else
{
dmax = ( *FL > *FC ) ? *FL : *FC ;
for ( i = 0 ; i < dmax ; i++ )
for ( j = 0 ; j < i ; j++ )
PermutMat( FMat + i * CMAX + j, FMat + j * LMAX + i ) ;
PermutMat(FL, FC) ;
return 1 ;
}
}
void PermutMat(int *x, int *y)
{
int aide ;
aide = *x ;
*x = *y ;
*y = aide ;
} |
Partager