程序代码:
#include <stdio.h> #define SIZE 10 void sortji(int * ar, int n); int main(void) { int datas[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int i; printf("array is : "); for (i = 0; i < SIZE; i++) printf("%d ", datas[i]); putchar('\n'); printf("array after sort is :"); sortji(datas, SIZE); for (i = 0; i < SIZE; i++) printf("%d ", datas[i]); return 0; } void sortji(int * ar, int n) { int i, j, temp; for (i = 0; i < n - 1; i++) { if((ar[i] % 2) == 0) continue; for (j = i + 1; j < n; j++) { if((ar[j] % 2) == 0) continue; if(ar[i] < ar[j]) { temp = ar[i]; ar[i] = ar[j]; ar[j] = temp; } } } }