I have a code made in C in which you enter data in a two-dimensional array and sort the rows, I also want you to order the columns
for example you enter: 9 8 7 6 5 4 3 2 1 and it looks like this: 7 8 9 4 5 6 1 2 3 that really is fine because I ordered each row, but I can not do it for the columns, make you visualize 1 2 3 4 5 6 7 8 9
I leave the code I have:
void introducirMatriz();
void visualizarMatriz();
void ordenarFilas();
void ordenarColumnas();
//Variable
int matriz[3][3] , aux;
int main()
{
printf("INTRODUCE DATOS EN LA MATRIZ BIDIMENSIONAL\n\n");
introducirMatriz();
printf("\n Matriz introducida\n\n");
visualizarMatriz();
ordenarFilas();
printf("\n Matriz ordenada\n\n");
visualizarMatriz();
return 0;
}
void introducirMatriz()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
printf("[%d][%d]: ",i,j);
scanf("%d",&matriz[i][j]);
}
}
}
void visualizarMatriz()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
printf(" %d",matriz[i][j]);
}
printf("\n");
}
}
void ordenarFilas()
{
for(int i=0;i<3;i++) //Metodo para ordenar la primera fila
{
for(int j=0;j<3-1-i;j++)
{
if(matriz[0][j]>matriz[0][j+1])
{
aux=matriz[0][j];
matriz[0][j]=matriz[0][j+1];
matriz[0][j+1]=aux;
}
}
}
for(int i=0;i<3;i++) //Metodo para ordenar la segunda fila
{
for(int j=0;j<3-1-i;j++)
{
if(matriz[1][j]>matriz[1][j+1])
{
aux=matriz[1][j];
matriz[1][j]=matriz[1][j+1];
matriz[1][j+1]=aux;
}
}
}
for(int i=0;i<3;i++) //Metodo para ordenar la tercera fila
{
for(int j=0;j<3-1-i;j++)
{
if(matriz[2][j]>matriz[2][j+1])
{
aux=matriz[2][j];
matriz[2][j]=matriz[2][j+1];
matriz[2][j+1]=aux;
}
}
}
}