Dummy commit to test new ssh key
[eleutheria.git] / homework / qsort2darray.c
blob28094c24c5f1b0c656ecac2af681bb152699459f
1 #include <stdio.h>
2 #include <stdlib.h>
4 /* Function prototypes */
5 void printarray(int a[3][3]);
6 int mycmp(const void *x, const void *y);
8 int main(void)
10 int i;
11 int a[3][3] = { { 1, 10, 3},
12 { 4, 0, 6},
13 {70, -3, 9}};
15 printf("UNSORTED\n");
16 printarray(a);
18 /* Sort array on a per-row basis */
19 for (i = 0; i < 3; i++)
20 qsort(a[i], 3, sizeof(int), mycmp);
22 printf("SORTED\n");
23 printarray(a);
25 return EXIT_SUCCESS;
28 void printarray(int a[3][3])
30 int i, j;
32 for (i = 0; i < 3; i++) {
33 for (j = 0; j < 3; j++)
34 printf("%4d", a[i][j]);
35 printf("\n");
39 int mycmp(const void *x, const void *y)
41 if (*(const int *)x > *(const int *)y)
42 return 1;
43 else if (*(const int *)x == *(const int *)y)
44 return 0;
45 else
46 return -1;