返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int tmp;
  7.     int n[6]={0,-33,49,-19,7,22};
  8.     cout<<"排序前: ";
  9.     for(int i=0; i<6; i++)
  10.         cout<<n[i]<<" ";
  11.     for(int i=0; i<5; i++)
  12.     {
  13.         for(int j=i+1; j<6; j++)
  14.      {
  15.             if(n[j]<n[i])
  16.      {
  17.              tmp=n[i];
  18.              n[i]=n[j];
  19.              n[j]=tmp;
  20.       }     
  21.      }
  22.     }
  23.      
  24.     cout<<endl;
  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

返回列表