#include "stdlib.h"
main()
{
int buf[21],byte[4][5];
int i,j,m,n;
int k=0;
srand((unsigned)time(NULL));
for(i=0;i<4;i++)
{
for(j=0;j<5;j++)
{
byte[i][j] = rand()%100;
buf[k] = byte[i][j];
k++;
printf("%d ",byte[i][j]);
}
printf("\n");
}
printf("after the sort the byte is \n");
for(i=0;i<20;i++)
{
m = buf[i];
for(j=i+1;j<20;j++)
{
if(m
m = buf[j];
buf[j] = buf[i];
buf[i] = m;
}
}
byte[i/5][i%5] = buf[i];
if(i%5==0) printf("\n");
printf("%d ", byte[i/5][i%5]);
}
}
感觉已经写得够精简且符合要求的一个代码了!
#include
void main()
{
int a[4][5],b[20],i,j,k=0,t;
for(i=0;i<4;i++)
for(j=0;j<5;j++)
{
scanf("%d",&a[i][j]);
b[k++]=a[i][j];
}
for(i=0;i
{
t=b[i];
b[i]=b[j];
b[j]=t;
}
k=0;
for(i=0;i<4;i++)
for(j=0;j<5;j++)
{
a[i][j]=b[k++];
printf("%6d",a[i][j]);
if(j==4)
printf("\n");
}
}