本帖最後由 蔡庭豪 於 2016-7-30 11:29 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int number[5],temp;
- for(int x=0;x<5;x++){
- cout<<"輸入第"<<x+1<<"數"<<endl;
- cin>>number[x];
- }
- cout<<"排序前"<<endl;
- for(int y=0;y<5;y++){
- cout<<number[y]<<",";
- }
- for(int i=0;i<4;i++){
-
- for(int j=0;j<4-i;j++){
-
- if(number[j]>number[j+1]){
- temp=number[j];
- number[j]=number[j+1];
- number[j+1]=temp;
- }
- }
- }
- cout<<"排序後"<<endl;
- for(int z=0;z<5;z++){
- cout<<number[z]<<",";
- }
- system("pause");
- return 0;
- }
複製代碼 |