1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <stdio.h> int main() { int a[10] = {1, 2, 3, 5, 6, 7, 8, 9, 10}; int t, m; printf("现有数组:"); for (int i = 0; i < 9; i++) { printf("%d ", a[i]); } printf("\n"); printf("输入一个数:"); scanf("%d", &m); for (int i = 0; i < 10; i++) { if (m < a[i]) { t = m; m = a[i]; a[i] = t; } else if (m > a[8]) a[9] = m; } printf("排序后:"); for (int i = 0; i < 10; i++){ printf("%d ", a[i]); } return 0; }
|