返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int tmp=0;
  7.     int n[6]={12,57,-6,-32,0,23};  
  8.     cout<<"排序前";
  9.     for(int i=0;i<6;i++)
  10.     {
  11.     cout<<n[i]<<" ";
  12.     }
  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.          {
  28.          cout<<n[i]<<" ";
  29.          }
  30.          cout<<endl;
  31.    system("pause");
  32.      return 0;   
  33. }
複製代碼

TOP

返回列表