返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int seq[6]={12,-18,666,-9,35,-230};
  7.     int tmp;
  8.     cout<<"排序前: ";
  9.     for(int i=0; i<6; i++)
  10.     {
  11.         cout<<seq[i]<<" ";
  12.     }
  13.     for(int i=0; i<5; i++)
  14.     {
  15.         for(int j=i+1; j<6; j++)
  16.         {
  17.             if(seq[j]<seq[i])
  18.             {
  19.                 tmp=seq[i];
  20.                 seq[i]=seq[j];
  21.                 seq[j]=tmp;
  22.             }
  23.         }
  24.     }
  25.     cout<<endl;
  26.     cout<<"排序後: ";
  27.     for(int i=0; i<6; i++)
  28.     {
  29.         cout<<seq[i]<<" ";
  30.     }
  31.     cout<<endl;
  32.     system("pause");
  33.     return 0;
  34. }
複製代碼

TOP

返回列表