- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int seq[6]={12,-18,666,-9,35,-230};
- int tmp;
- cout<<"排序前: ";
- for(int i=0; i<6; i++)
- {
- cout<<seq[i]<<" ";
- }
- for(int i=0; i<5; i++)
- {
- for(int j=i+1; j<6; j++)
- {
- if(seq[j]<seq[i])
- {
- tmp=seq[i];
- seq[i]=seq[j];
- seq[j]=tmp;
- }
- }
- }
- cout<<endl;
- cout<<"排序後: ";
- for(int i=0; i<6; i++)
- {
- cout<<seq[i]<<" ";
- }
- cout<<endl;
- system("pause");
- return 0;
- }
複製代碼 |