c语言比较十个数大小冒泡法,【C语言】用选择法、冒泡法分别对10个整数从小到大排序...

【C语言】用选择法对10个整数从小到大排序:

#include #include /* run this program using the console pauser or add your own getch, system("pause") or input loop */

void SelectSort(int array[], int length){

int i, j, min, temp;

for(i=0; imin = i;                                                     //记录最小元素位置

for(j=i+1; jif(array[j]}

if(min!=i){                                                  //与第i个位置交换

temp = array[i];

array[i] = array[min];

array[min] = temp;

}

}

}

int main(int argc, char *argv[]) {

int array_length = 10;

int a[array_length];

int i;

printf("请输入10个整数:");

for(i=0; iscanf("%d", &a[i]);

}

SelectSort(a, array_length);

printf("排序后的元素为:\n");

for(i=0; iprintf("%d ", a[i]);

}

printf("\n");

return 0;

}

c语言比较十个数大小冒泡法,【C语言】用选择法、冒泡法分别对10个整数从小到大排序..._第1张图片

【C语言】用冒泡法对10个整数从小到大排序:

#include #include #include /* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {

int i, j, a[10], temp;

printf("请输入10个整数:");

for(i=0; i<10; i++){

scanf("%d", &a[i]);

}

for(i=0; i<9; i++){

for(j=0; j<9; j++){

if(a[j]>a[j+1]){

temp = a[j];

a[j] = a[j+1];

a[j+1] = temp;

}

}

}

printf("排序后的数字为:");

for(i=0; i<10; i++){

printf("%d ", a[i]);

}

return 0;

}

c语言比较十个数大小冒泡法,【C语言】用选择法、冒泡法分别对10个整数从小到大排序..._第2张图片

你可能感兴趣的:(c语言比较十个数大小冒泡法)