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
|
#include <stdio.h>
#include <stdlib.h>
typedef struct matrice{
int** grid;
int* d;
}matrice;
void alloc2D(int** s, int m, int n){
s=malloc(m*sizeof(int*));
int i;
for(i=0;i<m;i++)
s[i]=malloc(n*sizeof(int));
}
void alloc1D(int* s, int n){
s=malloc(n*sizeof(int));
}
void assign(int** a,int m, int n){
int i,j;
for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf("entrer un nombre: ");
scanf("%d",&a[i][j]);
}
}
}
void create_matriceA(matrice A, int m, int n){
alloc2D(A.grid, m, n);
alloc1D(A.d,2);
A.d[0]=m; A.d[1]=n;
assign(A.grid, A.d[0], A.d[1]);
}
void mineur_aij(int** Mij, int i, int j, matrice A){
i=i-1;
j=j-1;
alloc2D(Mij,2,2);
int i1,i2,ai,aj;i1=i2=0;
for(ai=0;ai<A.d[0];ai++){
if(ai==i)
continue;
for(aj=0;aj<A.d[1];aj++){
if((ai-1==i & aj==j) || (ai+1==i & aj==j))
continue;
Mij[i1][i2]=A.grid[ai][aj];
i2++;
if(i2==2){
i1++;
i2=0;
}
}
}
}
void print_Mnxn(int** A,int n1, int n2){
int i,j;
for(i=0;i<n1;i++){
for(j=0;j<n2;j++){
printf(" %d",A[i][j]);
}
}
}
int main(){
int** a;
alloc2D(a,3,4);//la ok
assign(a,3,4);//la, il crash juste après le saisi du 1er nombre avec une valeur de retour: 255 x (0XFF)
return 0;
} |
Partager