#include
void Find(int a[][5],int key,int row,int col);
int main()
{
int matrix[5][5] = {{0,1,2,3,4},{5,6,7,8,9},{11,12,13,14,15},{16,17,18,19,20},{21,22,23,24,25}};
int temp[25];
int i;
int j;
int k = 0;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 5; j++)
{
temp[k++] = matrix[i][j];//放到一维数组方便排序
}
}
int num;
for (i = 0; i < 24; i++)//排序从小到大
{
k = i;
for (j = i; j < 25; j++)
{
if (temp[j] < temp[k])
{
k = j;
}
}
if (i != k)
{
num = temp[i];
temp[i] = temp[k];
temp[k] = num;
}
}
Find(matrix,temp[0],4,0);
Find(matrix,temp[1],0,0);
Find(matrix,temp[2],0,4);
Find(matrix,temp[3],4,4);
Find(matrix,temp[24],2,2);
for (i = 0; i < 5; i++)
{
for (j = 0; j < 5; j++)
{
printf("%3d ",matrix[i][j]);
}
printf("\n");
}
return 0;
}
void Find(int a[][5],int key,int row,int col)//交换数组中两个元素的位置
{
int i;
int j;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 5; j++)
{
if (a[i][j] == key)
{
a[i][j] = a[row][col];
a[row][col] = key;
break;
}
}
}
}
追问这我们有些没学过
可不可以有单纯得二维数组
做