Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int values[] = { 88, 56, 100, 2, 25 };
  5.  
  6. int cmpfunc (const void * a, const void * b)
  7. {
  8. return ( *(int*)a - *(int*)b );
  9. }
  10.  
  11. int main()
  12. {
  13. int n;
  14.  
  15. printf("Before sorting the list is: \n");
  16. for( n = 0 ; n < 5; n++ ) {
  17. printf("%d ", values[n]);
  18. }
  19.  
  20. qsort(values, 5, sizeof(int), cmpfunc);
  21.  
  22. printf("\nAfter sorting the list is: \n");
  23. for( n = 0 ; n < 5; n++ ) {
  24. printf("%d ", values[n]);
  25. }
  26.  
  27. return(0);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement