- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int tmp;
- int r[6]={12,55,45,39,47,80};
- 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;
- }
複製代碼 |