- 主题
- 0
- 帖子
- 2
- 精华
- 0
- 积分
- 14
- C币
- 4 枚
- 在线时间
- 0 小时
- 注册时间
- 2009-8-30
- 最后登录
- 2009-8-30
- 性别
- 保密

- 主题
- 0
- 帖子
- 2
- C币
- 4 枚
- 在线时间
- 0 小时
|
发表于 2009-8-30 10:43:17
|显示全部楼层
- #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];
- }
复制代码 |
|