#include<iostream> #define swap(x,y,t)((t)=(x),(x)=(y),(y)=(t)) using namespace std; const int N=10; void sort(int b[],int count); int main() { int a[N]; cout<<endl <<"please input the "<<N<<"numbers:"<<endl; for(int i=0;i<N;i++) cin>>a[i]; cout<<endl <<"the original numbers you have inputed are: "<<endl; for(i=0;i<N;i++) cout<<" "<<a[i]; cout<<endl <<"After sorting the numbers ,the numbers are:"<<endl; sort(a,N); return 0; } void sort(int b[],int count) { int t,tempt; for(int i=0;i<count;i++) { t=count-i-1; for(int j=0;j<t;j++) { if(b[j]>b[j+1]) swap(b[j],b[j+1],tempt); } } for(i=0;i<N;i++) cout<<" "<<b[i]; }

评论