- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int num;
- int l[6]={0,-35,48,-13,7,22};
- cout<<"排序前: ";
- for(int i=0; i<6; i++)
- cout<<l[i]<<" ";
- for(int i=0; i<5; i++)
- {
- for(int j=i+1; j<6; j++)
- {
- if(l[j]<l[i])
- {
- num=l[i];
- l[i]=l[j];
- l[j]=num;
- }
- }
- }
- cout<<endl;
- cout<<"排序後: ";
- for(int i=0; i<6; i++)
- cout<<l[i]<<" ";
- cout<<endl;
- system("pause");
- return 0;
- }
複製代碼 |