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