#include<iostream>
using namespace std;
int main()
{
int a[10], i ,j;
for (i=0; i < 10; i++)
cin >> a[i];
for (i = 0; i < 10; i++)
{
for (j = i + 1; j < 10; j++)
if (a[i] > a[j])//按从小到大的顺序排序
{
int t;
t = a[i];
a[i] = a[j];
a[j] = t;
}
cout << a[i] << " ";
}
cout << endl;
for (i = 0; i < 10; i++)
{
for (j = i + 1; j < 10; j++)
if (a[i] < a[j])//按从大到小的顺序排序
{
int t;
t = a[i];
a[i] = a[j];
a[j] = t;
}
cout << a[i]<<" ";
}
return 0;
}
用选择法对十个整数排序
最新推荐文章于 2022-12-15 22:36:36 发布