#include <stdio.h> int main() { int n = 0; scanf("%d", &n); if (n <= 0 || n > 50) { printf("输入的数组元素个数不合理,请重新输入一个在 1 到 50 之间的数。\n"); return 0; } int arr[50] = {0}; int i = 0; for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } int left = 0; int right = n - 1; for (i = 0; i < n - 1; i++)//冒泡排序,正序排序 { int j = 0; for (j = 0; j < n - i - 1; j++) { if(arr[j] > arr[j+1]) { int t = arr[j]; arr[j] = arr[j+1]; arr[j+1] = t; } } } while (left < right) {//将数组内的元素进行倒置 int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; left++; right--; } for (i = 0; i < 5; i++) { printf("%d ", arr[i]); } return 0; }