题目链接:http://acm.ocrosoft.com/problem.php?cid=1172&pid=3
题目描述
用冒泡法从小到大排序
输入
10个整数
输出
由小到大排序的10个整数
样例输入
5 7 -3 21 -43 67 321 33 51 0
样例输出
-43 -3 0 5 7 21 33 51 67 321
#include<bits/stdc++.h> using namespace std; int main(){ int a[11]; for(int i=0;i<10;i++){ cin>>a[i]; } for(int i=0;i<9;i++){ int temp; for(int j=0;j<9-i;j++){ if(a[j]>a[j+1]){ temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; //swap(a[j],a[j+1]); } } } for(int i=0;i<10;i++){ cout<<a[i]<<" "; } cout<<endl; }