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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| #include <stdio.h>
#include <conio.h>
typedef struct ele {
int l; /*indice de la ligne*/
int c; /*indice de la colonne*/
float e; /*l'élément d'indice (l, c)*/
struct ele *suiv; /*null ou adresse de la prochaine structure*/
} ELE;
typedef struct el {
int lig; /*nbre de ligne de la matrice reelle*/
int col; /*nbre de ligne de la matrice reelle*/
ELE *M ; /*adrss de la première variable de type ELE qui contient les informations sur /*l'élément non nul de la matrice réelle*/
} Matrix;
/*void Creation(int N,int M,float A[50][50])
{
int I, J; /* indices courants */
/* Saisie des donnees /
for (I=0; I<N; I++)
for (J=0; J<M; J++)
{
printf("Element[%d][%d] : ",I,J);
scanf("%f",A[I][J]);
}
}*/
/*void affichage(float** A,int N,int M) /* Affichage de la matrice /
{
int I,J;
for (I=0; I<N; I++)
{
for ( J=0; J<M; J++)
printf("%3f", A[I][J]);
printf("\n");
}
}
ELE *nouv_maillon(int l,int c,float e)
{
ELE *nouv =(ELE*)malloc(sizeof (ELE));
nouv->l=l;
nouv->c=c;
nouv -> e=e;
return nouv;
}
void Ajout (ELE **list , ELE *nouv)
{
ELE *tamp;
if (*list==NULL)
*list =nouv;
else
tamp=*list;
while (tamp->suiv)
tamp=tamp->suiv;
tamp->suiv=nouv;
//list=tamp;
//return list ;
}
Matrix passage1 (float**t,int N,int M)
{
ELE *fc,*list,*mail,*pc;
Matrix mx;
int i,j;
for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
if (t[i][j]!=0)
mail=nouv_maillon(i,j,t[i][j]);
Ajout(&fc,mail);
}
printf ("voici la forme compacte");
pc=fc;
while (pc)
{
printf("%3f",pc ->e);
pc=pc->suiv;
}
}
mx.lig=N;
mx.col=M;
mx.M =fc;
return mx;
}
void passage2(Matrix mx)
{
int N=mx.lig ,M=mx.col,i,j;
float** t;
ELE *p=mx.M;
for(i=0;i<N;i++)
for(j=0;j<M;j++)
t[i][j]=0;
while(p)
{
t[p->l][p->c]=p->e ;
p=p->suiv ;
}
/*for(i=0;i<N;i++)
{
for(j=0;j<M;j++)
{
if p->l ==i && p->c ==j )
t[i][j]=p->e;
else t[i][j]=0
(*Matrix.M)=(*Matrix.M)->suiv;
}
printf("voici la forme compacte")
while (*Matrix.M)
{
printf("%3f",(*Matrix.M) ->e);
(*Matrix.M)=(*Matrix.M)->suiv;
}
printf("voici la matrice réelle de la forme compacte");/
affichage(t,mx.lig,mx.col);
} */
main ()
{
float A[50][50]; /* matrice initiale */
int N, M; /* dimensions des matrices */
int I, J; /* indices courants */
Matrix comp;
printf("----------------------Saisie de La Taille de La matrice--------------\n");
printf("Nombre de lignes (max.50) : ");
scanf("%d", &N );
printf("Nombre de colonnes (max.50) : ");
scanf("%d", &M );
for (I=0; I<N; I++)
{
for (J=0; J<M; J++)
{
printf("Elément[%d][%d]: ",I,J);
scanf("%3.1f",A[I][J]);
printf("\n");
}
}
/*for (I=0; I<N; I++)
{
for ( J=0; J<M; J++)
printf("%3.1f", A[I][J]);
printf("\n");
} */
getch();
// Creation(N,M);
//affichage(A,N,M);
//passage1(A,N,M);
//passage2(comp);
getch();
return 0;
} |
Partager