# Thread: 2D array sorting from min. to max.

1. ## 2D array sorting from min. to max.

guyz i'm stucked outta here in a tiny problem but really it turned out to be a big one for me. its all about sorting a 2D array for example [3][3] from min. to max. with integars.
i've been only 2 monthes in C programmin so i think its for me may be its a hard one for now.
this is the code that i've done, but i dunno why doesnt it work, and if there any logical errors i hope to see the solutions for it
Code:

#include <stdio.h>
void main()
{
int x[3][3],i,j,m,k,tmp;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&x[i][j]);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
for(m=i;m<3;m++)
for(k=j+1;k<3;k++)
if(x[i][j]>x[m][k])
{
tmp=x[i][j];
x[i][j]=x[m][k]; x[d][f]=tmp;
}
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
printf("%d ",x[i][j]);

2. You should use code tags around your er...code. Also explain what you expect it to do and what it's doing now that you weren't expecting it to do. There's more than one way to "sort a 2D array" so we can't quite be sure what you're looking for. Maybe give some sample input and output.

However, I think you have more than logic errors going on here:
Code:
```if(x[i][j]>x[m][k])
{
tmp=x[i][j];
x[i][j]=x[m][k]; x[d][f]=tmp;
}```
d and f aren't declared anywhere so your program shouldn't even compile.