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