当前位置: 移动技术网 > IT编程>开发语言>C/C++ > c语言:编写冒泡排序,排序一个整形数组(从小到大)

c语言:编写冒泡排序,排序一个整形数组(从小到大)

2018年12月10日  | 移动技术网IT编程  | 我要评论

蓬蓬乳和空空指,网吧门女主角,千涩核工厂

程序:不妨按从小到大排序

#include <stdio.h>

int main ()

{

 int a[10];

 int i = 0;

 int j = 0;

 int t = 0;

 printf ("input 10 numbers:");

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

 {

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

 }

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

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

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

   {

    t = a[j];

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

    a[j+1] = t;

   }

 printf ("the sorted numbers:\n");

 //"the sorted numbers"表示排序的数字

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

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

 printf ("\n");

 return 0;

}

输出结果:

input 10 numbers:11 2 3 5 34 6 78 9 12 62

the sorted numbers:

2       3       5       6       9       11      12      34      62      78

 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网