选择排序
#include <stdio.h>
int main(){
int arr[9]={12,65,87,28,96,83,65,27,97};
int max = 0;
for (int i=0;i<9-1; i++){
max=i;
for(int j=i+1;j<9;j++){
if (arr[max]<arr[j])
{
max=j;
}
}
printf("%d\n",max);
int temp=arr[i];
arr[i]=arr[max];
arr[max]=temp;
for (int k=0; k<9; k++) {
printf("%d\t",arr[k]);
}
printf("\n");
}
return0;
}
|
|