输入3个数字,然后从大到小输出
我想好了好久,思路想出来了,可就是写不出来,望指点
程序代码:
#include<stdio.h>
const int LEN = 3;
void bubble_sort(int array[], int len);
int main(int argc, char** argv)
{
int a[LEN], i;
// input the nums
for(i=0;i<LEN;i++)
{
printf("input the %d number:", i);
scanf("%d",a+i);
}
// sort the array
puts("sorting...");
bubble_sort(a,LEN);
// output the nums
for(i=0;i<LEN;i++)
{
printf("numbers[%d]=%d\n",i,a[i]);
}
return 0;
}
/**
* The bubble sort
*/
void bubble_sort(int array[], int len)
{
int i,j, temp;
for(i=0;i<len;i++)
{
for(j=0;j<len;j++)
{
if( array[j-1] > array[j] )
{
// swap the array[j-1], array[j]
temp = array[j-1];
array[j-1] = array[j];
array[j] = temp;
}
}
}
}
抄了别人的冒泡排序,惭愧自己写不出了
[ 本帖最后由 神vLinux飘飘 于 2014-1-12 23:59 编辑 ]









