STANAANDREY

qsort C(predef)

May 6th, 2021
449
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data