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

TOP

返回列表