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

TOP

返回列表