- #include<iostream>
- using namespace std;
- void main()
- {
- int temp,i;
- int array[]={3,5,9,11,7,-9,32,20,123,103};
- cout<<"排序前的數組為:";
- for(i=0;i<10;i++)
- cout<<array[i]<<",";
- cout<<endl;
- for(int pass=0;pass<9;pass++)
- {
- for(i=0;i<9-pass;i++)
- {
- if(array[i]>array[i+1])
- {
- temp=array[i];
- array[i]=array[i+1];
- array[i+1]=temp;
- }
- }
- }
- cout<<"排序后的數組為:";
- for(i=0;i<10;i++)
- cout<<array[i]<<",";
- cout<<endl;
- }
復制代碼
|