返回列表 發帖
本帖最後由 廖秝瑜 於 2023-8-11 20:29 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;
  7.     int n[]={12,57,-6,-32,0,23};
  8.     cout<<"排序前: ";
  9.     for(int i=0; i<6; i++)
  10.     {
  11.         cout<<n[i]<<" ";
  12.     }
  13.         cout<<endl;
  14.         
  15.         
  16.         for(int i=0; i<=5; i++)
  17.         {
  18.                 for(int j=i+1; j<=6; j++)
  19.                 {
  20.                         if(n[j]<n[i])
  21.                         {
  22.                            a=n[j];
  23.                            n[j]=n[i];
  24.                            n[i]=a;
  25.                         }
  26.                  }
  27.         }
  28.         cout<<"排序後";
  29.         for(int i=0; i<6; i++)
  30.         {
  31.             cout<<n[i]<<" ";
  32.     }
  33.         cout<<endl;  
  34.                
  35.    
  36.    
  37.    
  38.    
  39.    
  40.     system("pause");
  41.     return 0;
  42. }
複製代碼

TOP

返回列表