返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;   
  4. int main()
  5. {
  6.     int n[]={12,57,-6,-32,0,23};
  7.     int tmp;
  8.     cout<<"排序前:";
  9.     for(int i=0;i<6;i++)
  10.         cout<<n[i]<<" ";
  11.     for(int i=0;i<5;i++)
  12.     {
  13.         for(int j=i+1;j<6;j++)
  14.         {
  15.             if(n[j]<n[i])
  16.             {
  17.                 tmp=n[j];
  18.                 n[j]=n[i];
  19.                 n[i]=tmp;
  20.             }  

  21.         }   
  22.     }
  23.     cout<<"排序後:";
  24.     for(int i=0;i<6;i++)
  25.         cout<<n[i]<<" ";
  26.     system("pause");
  27.     return 0;
  28. }
複製代碼

TOP

返回列表