氣泡法排序 輸入N個數字 由小到大排序

/**********************************************************
  氣泡法排序 輸入N個數字 由小到大排序

  <Edison wong>. QQ139767
**********************************************************/
#include<stdio.h>
#define N 10
void main()
{
 int a[N+1],b,c,temp;
 printf("請輸入10個數字:/n");
 for(b=1;b<=N;b++)
  scanf("%d",&a[b]);
 for(b=1;b<=N-1;b++)
  for(c=1;c<=N-b;c++)
   if(a[c]>a[c+1])
   {
    temp=a[c];
    a[c]=a[c+1];
    a[c+1]=temp;
   }
 for(b=1;b<=N;b++)
  printf("%d ",a[b]);
 putchar('/n9');

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章