#include <stdio.h>void main(){int a[10]={2,4,2,5,6,7,2,5,2,4};int i,j,k,t;for(i=0;i<9;i++){k=i;for(j=i+1;j<10;j++)if(a[j]<=a[i])k=j;if(k!=i){t=a[i];a[i]=a[k];a[k]=t;}}for(i=0;i<=9;i++)printf("a[%d]=%d\n",i,a[i]);}
跪求错在哪???
已经修改完成,请采纳:
#include <stdio.h>
void main()
{
int a[10]={2,4,2,5,6,7,2,5,2,4};
int i,j,k,t;
for(i=0;i<9;i++)
{k=i;
for(j=i+1;j<10;j++)
if(a[j]<=a[k])k=j; //这一行中比较对象应为a[k]
if(k!=i){t=a[i];a[i]=a[k];a[k]=t;}
}
for(i=0;i<=9;i++)
printf("a[%d]=%d\n",i,a[i]);
}