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

TOP

返回列表