返回列表 發帖
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int tmp;
  6.     int n[]={12,57,-6,-32,0,23};
  7.    
  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.         cout<<"第"<<i+1<<"次:";
  26.         for(int a=0;a<=5;a++)
  27.         {
  28.             cout<<n[a]<<" ";
  29.         }
  30.         cout<<endl;   
  31.     }
  32.    
  33.     cout<<"排序後: ";
  34.     for(int i=0; i<6; i++)
  35.     {
  36.             cout<<n[i]<<" ";
  37.     }
  38.         cout<<endl;
  39.       
  40.     system("pause");
  41.     return 0;
  42. }
複製代碼

TOP

返回列表