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

TOP

返回列表