#include #include #include #include #define R_MAX 100 #define C_MAX 100 void read_insert(float mat[R_MAX][C_MAX], int *dim_r, int *dim_c); void column(float mat[R_MAX][C_MAX], int *dim_r, int *dim_c,float valcol[C_MAX]); void scambia(float *x, float *y); void sort_col(float mat[R_MAX][C_MAX], int dim_r, int dim_c, float valcol[C_MAX]); void stampa(float mat[R_MAX][C_MAX], int dim_r, int dim_c); void stampafile(); int main(int argc, char const *argv[]) { float matrix[R_MAX][C_MAX]; float valcol[C_MAX]; int dim_r,dim_c; read_insert(matrix,&dim_r,&dim_c); column(matrix, &dim_r, &dim_c, valcol); sort_col(matrix, dim_r,dim_c,valcol); stampa(matrix,dim_r,dim_c); return 0; } void read_insert(float mat[R_MAX][C_MAX], int *dim_r, int *dim_c){ printf("Inserisci le dimensioni della matrice:\nRighe:"); scanf("%d", dim_r); printf("Colonne:"); scanf("%d", dim_c); int i,j; for(i=0;i<*dim_r;i++){ for(j=0;j<*dim_c;j++){ mat[i][j]=rand()%100; } } } void column(float mat[R_MAX][C_MAX], int *dim_r, int *dim_c,float valcol[C_MAX]){ int i,j; int half; int count=0; int k=0; if (*dim_c%2==0) half=*dim_c/2; else half=(*dim_c/2)+1; stampa(mat,*dim_r,*dim_c); printf("half = %d\n",half ); for(i=0;i<*dim_c;i++){ while(count!=half){ printf("Inizio while\n"); valcol[i]=mat[k][i]; printf("valcol = %f\nmat[k][i] = %f", valcol[i], mat[k][i]); for(j=0;j<*dim_r;j++){ printf("Inizio for\n"); if(valcol[i]>=mat[j][i]){ count++; printf("count = %d\n",count ); } } if(count!=half){ count=0; } k++; } count=0; k=0; /* do { valcol[i]=mat[k][i]; for(j=0;j<*dim_r;j++){ printf("1 %d %d \n",count,k ); if (mat[j][i]<=valcol[i]) { count++; printf("2 %d %d \n",count,k ); } } k++; printf("3 %d %d \n",count,k ); }while(count==half && k==3); count=0; k=0;*/ } for(i=0;i<*dim_c;i++){ printf("Valore medio[%d]:%f\n",i, valcol[i] ); } } void scambia(float *x, float *y) { float z; z = *x; *x = *y; *y = z; } void sort_col(float mat[R_MAX][C_MAX], int dim_r, int dim_c, float valcol[C_MAX]){ int i, j, z, min; int temp[C_MAX]; for (i=0; i