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

               


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

#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

 

 


本文出自 “岩枭” 博客,请务必保留此出处http://yaoyaolx.blog.51cto.com/10732111/1712000

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/qq_43667626/article/details/86410698
今日推荐