Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int compare (const void * a, const void * b)
- {
- return ( *(int*)a - *(int*)b );
- }
- int main()
- {
- int data[]= {9,8,7,10};
- const int LENGTH=4;
- qsort(data, LENGTH, sizeof(int), compare);
- for (int i=0; i<LENGTH; i++)
- printf("%d %d\n",i, data[i]);
- if (LENGTH%2) // length is odd
- printf("%d\n", data[LENGTH/2]);
- else // length is even - take average of middle two
- printf("%f\n", (data[LENGTH/2-1]+data[LENGTH/2])/2.0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment