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]);