返回列表 發帖
  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.    
  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.             if(n[j]<n[i])
  20.             {
  21.                 tmp=n[j];
  22.                 n[j]=n[i];
  23.                 n[i]=tmp;
  24.             }  

  25.         }
  26.          
  27.     }
  28.    
  29.      cout<<"排序後:" ;
  30.     for(int i=0; i<6; i++)
  31.    {
  32.       cout<<n[i]<<" ";         
  33.    }  

  34.    cout<<endl;
  35.       
  36.    
  37.    
  38.    
  39.     system("pause");      
  40.     return 0;              
  41. }
複製代碼

TOP

返回列表