0

Sorting in C

I have array with 20 digits I need arrange items that are in pair positions descending The first "for" I set up correctly, but I do not know how to proceed Help me please Code: #include <stdio.h> #include <stdlib.h> int a[20]={12,0,3,34,2,99,81,21,75,7,48,65,31,95,77,43,50,88,4,46}; int comp (const int *, const int *); int main(void) { int i; printf("Original array: "); for (i=2; i<20; i+=2) printf("%d ",a[i]); printf ("\n"); qsort(a, 20, sizeof (int), (int(*) (const void *, const void *)) comp); printf("Sorted array: "); for(i = 2; i <20; i+=2) printf("%d ", a[i]); return 0; } int comp (const int *i, const int *j) { return *j - *i; }

13th Nov 2018, 9:45 PM
Alex
Alex  - avatar
1 Respuesta
0
Are you wanting to sort the whole array or just the pairs? (ie { 1, 5, 3, 2, 6, 9} >> {5, 1, 3, 2, 9, 6} or { 1, 5, 3, 2, 6, 9} >> {9, 6, 5, 3, 2, 1} )
17th Aug 2022, 11:13 PM
William Owens
William Owens - avatar