- #include<cstdlib>
- #include<iostream>
- #include<ctime>
- using namespace std;
- int main()
- {
- int z;
- int x[]={12,57,-6,-32,0,23};
- cout<<"排序前:";
- for(int i=0; i<6; i++)
- {
- cout<<x[i]<<" ";
- }
- cout<<endl;
- for(int i=0;i<5;i++)
- {
- for(int j=i+1; j<6; j++)
- {
- if(x[j]<x[i])
- {
- z=x[j];
- x[j]=x[i];
- x[i]=z;
- }
- }
- }
- cout<<"排序後: ";
- for(int i=0;i<6;i++)
- {
- cout<<x[i]<<" ";
- }
- cout<<endl;
- system("pause");
- return 0;
- }
複製代碼 |