冒泡排序

冒泡法对10个数由小到大进行排序,冒泡法的基本思路是:如果要对n个数进行冒泡排序,那么要进行n-1次比较,在第1躺比较中要进行n-1次两两比较,在第j躺比较中要进行n-j次两两比较

#include <stdio.h>

int main(void)
{
        int i,j,t,a[11];

        for(i=1;i<10;i++)
        {
                scanf("%d",&a[i]);
        }

        for(i=1;i<10;i++)
        {
                printf("%5d",a[i]);
        }

        printf("\n");

        for(i=1;i<10;i++)
        {
                for(j=1;j<11-i;j++)
                {
                        if(a[j] > a[j+1]){
                                t = a[j];
                                a[j] = a[j+1];
                                a[j+1] = t;
                        }

                }
        }

        for(i=1;i<10;i++)
        {
                printf("%5d",a[i]);
        }

        printf("\n");

        return 0;
}