指针求解 不知道错哪
程序代码:#include<stdio.h>
main()
{
void array(int x[5][5]);
int i,j,a[5][5];
printf("please input array\n");
for(i=0;i<5;i++)
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
array(a);
printf("follows are the array changer\n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%3d",a[i][j]);
printf("\n");
}
}
void array(int x[5][5])
{
int i,j,*h=x[0],*k[25],t,l=0,m,*n;
for(i=0;i<5;i++) /*must analyze clearly*/
for(j=0;j<5;j++)
if(*h<*(x[i]+j+1)) /*if this line change 'h' which in the bracket into 'x[i]+j' ,it would be wrong */
h=x[i]+j+1;
for(i=0;i<5;i++) /*get all of the elements' address*/
for(j=0;j<5;j++)
k[l++]=&x[i][j];
for(i=0;i<25;i++) /*arrange the address*/
{
m=i;
for(j=0;j<25;j++)
if(*k[m]>*k[j])
m=j;
n=k[i];
k[i]=k[m];
k[m]=n;
}
t=x[2][2]; x[2][2]=*h; *h=t;
t=x[0][0]; x[0][0]=*k[0]; *k[0]=t;
t=x[4][0]; x[4][0]=*k[1]; *k[1]=t;
t=x[0][4]; x[0][4]=*k[2]; *k[2]=t;
t=x[4][4]; x[4][4]=*k[3]; *k[3]=t;
}
一个5×5矩阵 把最大的数放在中间 最小的四个数按照从上倒下 左到右顺序放置










