Compilation mai erreur a l execution

touny23 Messages postés 9 Date d'inscription vendredi 23 décembre 2005 Statut Membre Dernière intervention 30 décembre 2005 - 25 déc. 2005 à 10:38
luhtor Messages postés 2023 Date d'inscription mardi 24 septembre 2002 Statut Membre Dernière intervention 28 juillet 2008 - 25 déc. 2005 à 15:27
bon j ai fai une amélioration de mon programme . je galere un peu avec le C mai bon c est un projet , soit disan la base de la methode num.(je croi qu on va en chier )
si vous pouviez m aider , il doi y avoir des erreurs (peut etre dans les indices des boucles for meme si j ai verifié et revérifié) merci d avance

si vous pouviez aussi m expliquer la différence si il y en a une entre M.type et M->type par exemple

#include<stdio.h>
#include<stdlib.h>


typedef struct {
int dim1;
int dim2;
int type;
double **tab;
}matrice;


void creation (matrice *M)
{
int i,j;
printf("creation d'une matrice!!!!\n");
printf("entrer la 1e dimension=");
scanf("%d",&M->dim1);
printf("entrer la 2e dimension=");
scanf("%d",&M->dim2);
printf("entrer le type de la matrice=\n");
printf("1-matrice pleine\n");
printf("2-matrice triangulaire inférieure\n");
printf("3-matrice triangulaire supérieure\n");
scanf("%d",&M->type);
if(M->type==1){
M->tab=(double **)malloc(M->dim1*sizeof(double *));
for(i=0;i<M->dim1;i++)
M->tab[i]=(double *)malloc(M->dim2*sizeof(double));
printf("chiffre de la matrice??");
for(i=0;i<M->dim2;i++){
printf("%d e ligne\n",i);
for(j=0;j<M->dim1;j++)scanf("%lf",&M->tab[i][j]);
}
}



if(M->type==2){ /*matrice de type triangulaire inf. */
M->tab=(double **)malloc(M->dim1*sizeof(double *));
for(i=0;i<M->dim1;i++)
M->tab[i]=(double *)malloc(M->dim2*sizeof(double));
/*on detruit la partie supérieure pour liberer de la place */
for(i=0;i<(M->dim2)-1;i++){
for(j=i+1;j<M->dim1;j++)free(M->tab[j]);
}
/*on rempli la partie inferieure */
printf("chiffres de la matrice");
for(i=0;i<M->dim2;i++){
printf("%d e ligne\n",i);
for(j=0;j<=i;j++)scanf("%lf",&M->tab[i][j]);
}
}

if(M->type==3){ /*matrice de type triangulaire sup. */
M->tab=(double **)malloc(M->dim1*sizeof(double *));
for(i=0;i<M->dim1;i++)
M->tab[i]=(double *)malloc(M->dim2*sizeof(double));
for(i=1;i<M->dim2;i++){
for(j=0;jtab[j]);
}
printf("chiffres de la matrice");
for(i=0;i<M->dim2;i++){
printf("%d e ligne\n",i);
for(j=i;j<M->dim1;j++)scanf("%lf",&M->tab[i][j]);
}

}




}


void affichage(matrice M)
{
int i,j;
if(M.type==1){
for(i=0;i<M.dim2;i++){
for(j=0;j<M.dim1;j++){printf("%lf",M.tab[i][j]);}
printf("\n");
}
}
if(M.type==2){
for(i=0;i<M.dim2;i++){
for(j=0;j<=i;j++)printf("%lf",M.tab[i][j]);
printf("\n");
}
}
if(M.type==3){
for(i=0;i<M.dim2;i++){
for(j=i;j<M.dim1;j++)printf("%lf",M.tab[i][j]);
printf("\n");
}
}




}


void produit(matrice M,matrice N)
{
int i,j,k;
if(M.type==1&&N.type==2){ /* on cree la matrice produit, les 2 matrices ont les meme dimensions */
matrice O;
O.type=M.type;
O.dim1=M.dim1;
O.dim2=M.dim2;
O.tab=(double **)malloc(M.dim1*sizeof(double *));
for(i=0;i<M.dim1;i++)
O.tab[i]=(double *)malloc(M.dim2*sizeof(double));
/*on fait le produit des 2 matrices */
O.tab[0][0]=0;
for(i=0;i<M.dim2;i++)
for(j=0;O.tab[i][j]=0,j<N.dim1;j++)
for(k=0;k<M.dim1;k++)
O.tab[i][j]=M.tab[i][k]*N.tab[k][j];
}
if(M.type==1&&N.type==2){ /* on copie la matrice triangulaire dan une autre matrice
en y ajoutant les zéros ,tout ça pour effectuer le produit */
matrice P;
P.type=M.type;
P.dim1=N.dim1;
P.dim2=N.dim2;
P.tab=(double **)malloc(P.dim1*sizeof(double *));
for(i=0;i

1 réponse

luhtor Messages postés 2023 Date d'inscription mardi 24 septembre 2002 Statut Membre Dernière intervention 28 juillet 2008 6
25 déc. 2005 à 15:27
J'ai pas regargé en détail, mais quand tu fais "affichage(O)". Ya rien dans "O" !!



Quand M est un objet -> M.type

Quand M est un pointeur d'objet -> (M->type <=> (*M).type)
0
Rejoignez-nous