排序

#include”stdio.h”

int main()

{

int buf[100] = { 1,6,88,99,22,44,11,11 ,99};

int tmp = 0;

int key = 0;

int j = 1;

int i = 0;

int index = 0;

printf_s(“hello work 请输入数据\n”);

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

{

key = buf[i];

//每次找最小的

for (j=i; j < 9; j++)

{

if (key > buf[j])

{

key  = buf[j];

index = j;

}

}

//交换数据

if (key < buf[i])

{

tmp = buf[i];

buf[i] = key;

buf[index] = tmp;

}

}

 

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

{

printf_s(“%d \n”, buf[i]);

}

getchar();

return  0;

}

点赞