冒泡排序對N個數由小到大排序


#include <stdio.h>
#define N 5
void main()
{
    int a[N];
    int i,j,temp;
    printf("請輸入待排序的數據: \n");
    for (i=0;i<N;i++)
        scanf("%d",&a[i]);
    for (i=1;i<=N-1;i++)
        for (j=0;j<N-i;j++)
        if (a[j]>a[j+1])
    {
        temp=a[j];
        a[j]=a[j+1];
        a[j+1]=temp;
    }
    printf("排序后的數據: \n");
    for(i=0;i<N;i++)
        printf("%d",a[i]);
    printf("\n");
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM