返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a[5] , tmp;
  7.     for ( int i=0 ; i<5 ; i++ )
  8.     {
  9.         cout<<"請輸入第"<<i+1<<"個數字: ";
  10.         cin>>a[i];
  11.     }
  12.     cout << "您所輸入的數字順序: ";
  13.     for ( int i=0 ; i<5 ; i++ )
  14.     {
  15.         cout << a[i] << " , " ;
  16.     }
  17.         for( int i=0 ; i<5-1 ; i++ )
  18.     {
  19.         for( int j=0 ; j<5-i-1 ; j++ )        
  20.         {
  21.             if( a[j] > a[j+1] )  
  22.             {
  23.                 tmp    = a[j]  ;  
  24.                 a[j]   = a[j+1];  
  25.                 a[j+1] = tmp   ;  
  26.             }
  27.         }
  28.     }
  29.     cout << endl;
  30.     cout << "系統自動排序後的數: " ;
  31.     for ( int i=0 ; i<5 ;i++ )
  32.     {
  33.         cout << a[i] << " , " ;
  34.     }
  35.     cout << endl;
  36.     system("pause");
  37.     return 0;
  38. }
複製代碼

TOP

返回列表