[cpp] view plain copy //冒泡法对数排列(由小到大) #include<iostream> #include<iomanip> using namespace std; int main() { int a[10]={2,3,4,8,9,1,41,58,15,20}; int i,j,temp; for(j=0;j<9;j++) for(i=0;i<9-j;i++)//两次循环,让最大者到最后 { if(a[i]>a[i+1]) {temp=a[i];a[i]=a[i+1];a[i+1]=temp;} } for(i=0;i<10;i++) cout<<setw(9)<<a[i]<<endl; return 0; }