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

TOP

返回列表