Advertisement
STANAANDREY

qsort C(predef)

May 6th, 2021
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4.  
  5. int cmp(const void *a, const void *b) {
  6.     return *(int*)a - *(int*)b;
  7. }
  8.  
  9. int main() {
  10.     int n;
  11.     scanf("%d", &n);
  12.     int *arr = (int*)calloc(n, sizeof(int));
  13.     assert(arr != NULL);
  14.     for (int i = 0; i < n; i++) {
  15.         scanf("%d", &arr[i]);
  16.     }
  17.     qsort(arr, n, sizeof(int), cmp);
  18.     for (int i = 0; i < n; i++) {
  19.         printf("%d ", arr[i]);
  20.     }
  21.     return 0;
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement