Trying to sort matrix such that it has value in ascending order.
But outcome is coming :
Code:
Matrix after sorting :
2,2,2,2,
2,2,2,2,
2,2,2,2,
2,2,2,2,
Can't find whats wrong.
My code :
[code]
Trying to sort matrix such that it has value in ascending order.But outcome is coming :
Code:
Matrix after sorting :
2,2,2,2,
2,2,2,2,
2,2,2,2,
2,2,2,2,
Can't find whats wrong.
My code :
Code:
#include<stdio.h>
void sort(int [][4]);
int main( void)
{
int i,j,Matrix[4][4] ={ /*Initializing array*/
2,4,3,67,
6,8,2,7,
9,12,6,4,
12,4,5,7
};
sort(Matrix);
printf ( "Matrix after sorting : \n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("%d,",Matrix[i][j]);
}
printf("\n");
}
}
void sort(int a[4][4])
{
int b[4][4] ;
int i,j,x,y,temp;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
b[i][j]=a[i][j];
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
for(x=i;x<4;x++)
{
for(y=j;y<4;y++)
{
if (a[i][j] > b[x][y])
temp = b[x][y];
b[x][y]= a[i][j];
a[i][j]= temp;
}
}
}
}
}