楼主似乎是要写冒泡排序。修改代码如下:
#include<stdio.h>
int main( void )
{
int i, j, k;
int a[5] = {21, 12, 13, 31, 37};
for ( i = 4; i >= 0; i-- ) {
for ( j = 0; j < i; j++ ) {
if ( a[j] < a[j - 1] ) {
k = a[j];
a[j] = a[j + 1];
a[j + 1] = k;
}
}
printf( "%d,", a[i] );
}
return 0;
}
#include<stdio.h>
int main( void )
{
int i, j, k;
int a[5] = {21, 12, 13, 31, 37};
for ( i = 4; i >= 0; i-- ) {
for ( j = 0; j < i; j++ ) {
if ( a[j] < a[j - 1] ) {
k = a[j];
a[j] = a[j + 1];
a[j + 1] = k;
}
}
printf( "%d,", a[i] );
}
return 0;
}