本题要求将给定的n个整数从大到小排序后输出。
输入格式:
输入第一行给出一个不超过10的正整数n。第二行给出n个整数,其间以空格分隔。
输出格式:
在一行中输出从大到小有序的数列,相邻数字间有一个空格,行末不得有多余空格。
输入样例:
4
5 1 7 6
输出样例:
7 6 5 1
#include<iostream>
using namespace std;
int main()
{
int arr[10];
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i < n - 1; i++)
{
int max = i;
for (int j = i + 1; j < n; j++)
{
if (arr[i] > arr[j])
max = j;
}
int temp;
temp =arr[max];
arr[max] =arr[i] ;
arr[i] = temp;
}
for (int i = n - 1; i >= 0; i--)
{
if (i == 0)
cout << arr[i];
else
cout << arr[i] << " ";
}
system("pause");
}