返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.         int tmp;
  7.         int a[6] = {12,24,68,52,-555,55};
  8.         cout << "排序前:";
  9.         for (int i = 0; i < 6; i++)
  10.         {
  11.                 cout << a[i] << "\t";
  12.         }
  13.         cout << endl;
  14.         for (int i = 0; i < 5; i++)
  15.         {
  16.                 for (int j = i + 1; j < 6; j++)
  17.                 {
  18.                         if (a[j] < a[i])
  19.                         {
  20.                          tmp = a[i];
  21.                          a[i] = a[j];
  22.                          a[j] = tmp;       
  23.                         }
  24.                 }
  25.         }
  26.         cout << "排序後:";
  27.         for (int i = 0; i < 6; i++)
  28.         {
  29.                 cout << a[i] << "\t";
  30.         }
  31.         cout << endl;
  32.         system ("pause");
  33.         return 0;
  34. }
複製代碼

TOP

返回列表