---
# System prepended metadata

title: Untitled

---

```clike=
#include <iostream>

using namespace std;

int main()
{   int i,j,k,n,p;
cout<<"首先請輸入要排序的數量，再來為相對應的數值"<<endl;
cin>>n;
    int a[n];//我把100改成n這樣就可以剛好容納要排序的組數
    for (k=0;k<n;k++){//變數只要聲明一次就好了
        cin>>p;
        a[k]=p;
    }
    cout << "初始設定=";
    for (k=0;k<5;k++){
        cout << a[k]<<"  ";
    }
    cout<<endl;

    for (i=1;i<=n;i++){
        for (j=0;j<n-i;j++){
            if (a[j]>a[j+1]){
                swap (a[j],a[j+1]);
            }
        }
        cout <<"第"<<i<<"次排列=";
        for (k=0;k<n;k++){
            cout <<a[k]<<"  ";
        }
        cout <<endl;
    }
    cout <<"陣列排列結果=";
    for (i=0;i<n;i++){
        cout <<a[i];
        if(i<n-1){
           cout <<"<";
        }
        else{
            return 0;//我增加了一個if~eise條件來顯示小於
        }
    }
}
```