代码如下:

 1#include <stdio.h>
 2#define N 10
 3int main(void)
 4{
 5      int a[N] = {5, 1, 8, 4, 0, 2, 9, 3, 6, 7};
 6      int i, flag, temp, j = N;
 7      do {
 8           flag = 0;
 9           for (i = 1; i < j; i++)
10          {
11               if (a[i - 1] > a[i])
12              {
13                   flag = 1;
14                   temp = a[i - 1];
15                   a[i - 1] = a[i];
16                    a[i] = temp;
17               }
18           }
19           j--;
20      } while (flag);
21      for (i = 0; i < N; i++)
22      {
23           printf("%5d", a[i]);
24      }
25     printf("n");
26}