- #include<iostream>
- #include<iomanip>
- using namespace std;
- int main()
- {
- int const len=4;//4可以改为其他数据个数
- int a[len],n,u;
- cout<<"请输入"<<len<<"个数字:";
- for (u=0;u<len;u++)
- {
- cin>>a[u];
- }
- for (n=0;n<len;n++)
- {
- int i;
- for (i=0;i<len;i++)
- {
- if (a[i+1]>=a[i])
- {
- int temp;
- temp=a[i];
- a[i]=a[i+1];
- a[i+1]=temp;
- }
- }
- }
- for (u=0;u<len;u++)
- {
- cout<<a[u]<<" ";
- }
- system("pause");
- }
- //该片段来自于http://www.codesnippet.cn/detail/160920135925.html
来源: http://www.codesnippet.cn/detail/160920135925.html