返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.   int n[] ={12,57,-6,-32,0,23},tmp;
  8.   cout<<"排序前:";
  9.   for(int i=0;i<5;i++)
  10.   {
  11.       cout<<n[i]<<" ";
  12.   }

  13.   cout<<endl;

  14.   for(int i=0; i<5; i++)
  15.   {
  16.         for(int j=i+1; j<6; j++)
  17.         {
  18.             if(n[j]<n[i])
  19.             {
  20.                 tmp=n[j];
  21.                 n[j]=n[i];
  22.                 n[i]=tmp;
  23.             }

  24.         }
  25.     }

  26. cout<<"排序後:";
  27.   for(int i=0;i<5;i++)
  28.         cout<<n[i]<<" ";
  29. cout<<endl;

  30.     system("pause");
  31.     return 0;
  32. }
複製代碼

TOP

返回列表