#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <stdlib.h> int main() { int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int len = sizeof(arr)/sizeof(arr[0]); int i = 0; int j = 0; for (; i < len - 1; i++) { for (j=0; j < len - i-1; j++) { if (arr[j] < arr[j + 1]) { int tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; } } } for (i = 0; i < len; i++) { printf("%d ", arr[i]); } system("pause"); return 0; }
时间: 2024-11-18 21:18:00