- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a[5] , tmp;
- for ( int i=0 ; i<5 ; i++ )
- {
- cout<<"請輸入第"<<i+1<<"個數字: ";
- cin>>a[i];
- }
- cout << "您所輸入的數字順序: ";
- for ( int i=0 ; i<5 ; i++ )
- {
- cout << a[i] << " , " ;
- }
- for( int i=0 ; i<5-1 ; i++ )
- {
- for( int j=0 ; j<5-i-1 ; j++ )
- {
- if( a[j] > a[j+1] )
- {
- tmp = a[j] ;
- a[j] = a[j+1];
- a[j+1] = tmp ;
- }
- }
- }
- cout << endl;
- cout << "系統自動排序後的數: " ;
- for ( int i=0 ; i<5 ;i++ )
- {
- cout << a[i] << " , " ;
- }
- cout << endl;
- system("pause");
- return 0;
- }
複製代碼 |