#include<iostream>
using namespace std;
int main()
{
const int maxNum = 6;
int n, a[maxNum], i, j;
cout << "请为数组元素赋值(6个整数):\n";
for (n = 0; n < maxNum; n++)
{
cin >> a[n];
if (a[n] == 7)
break;
}
for (i = 0; i < n - 1; i++)
for (j = i + 1; j < n; j++)
if (a[i] > a[j])
{
int t;
t = a[i];
a[i] = a[j];
a[j] = t;
}
cout << "升序排序后数组元素分别为:\n";
for (i = 0; i < n; i++)
cout << a[i] << "\t";
system("pause");
return 0;
}
Last modification:December 5th, 2018 at 07:19 pm
© 允许规范转载