fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int asc(const void *a, const void *b)
  5. {
  6. if(*(double *)a > *(double *)b) return 1;
  7. if(*(double *)a < *(double *)b) return -1;
  8. return 0;
  9. }
  10.  
  11. int main(void)
  12. {
  13. double c[5]={1.2,-3.4,5.9,-2.3,4.5};
  14. int size = sizeof(double);
  15. int length = sizeof(c) / size;
  16. qsort(c, length, size, asc);
  17. for(int i=0; i<length; i++)
  18. {
  19. printf("%f\n",c[i]);
  20. }
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
-3.400000
-2.300000
1.200000
4.500000
5.900000