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

TOP

返回列表