fork download
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <stdlib.h>
  4.  
  5. int comp(const void* a_, const void* b_) {
  6. int a = *(const int*)a_;
  7. int b = *(const int*)b_;
  8.  
  9. if (abs(a % 2) > abs(b % 2)) return -1;
  10.  
  11. if (abs(a % 2) < abs(b % 2)) return 1;
  12.  
  13. if (a % 2) return a - b;
  14. else return b - a;
  15. }
  16.  
  17.  
  18. int main() {
  19. int count;
  20. printf("count: ");
  21. scanf("%d", &count);
  22. int* array = malloc(sizeof(int) * count);
  23.  
  24. for (int i = 0; i < count; i++) {
  25. printf("%d element: ", i + 1);
  26. scanf("%d", &array[i]);
  27. }
  28.  
  29. qsort(array, count, sizeof(int), comp);
  30.  
  31. for (int i = 0; i < count; i++) {
  32. printf("%d ", array[i]);
  33. }
  34. }
  35.  
  36.  
Success #stdin #stdout 0s 5516KB
stdin
12
-1 2 -3 76 -24 22 -18 3 15 16
stdout
count: 1 element: 2 element: 3 element: 4 element: 5 element: 6 element: 7 element: 8 element: 9 element: 10 element: 11 element: 12 element: -3  -1  3  15  76  22  16  2  0  0  -18  -24