Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> /* printf */
- #include <stdlib.h> /* qsort, bsearch, NULL */
- int sumuj(int *A,int size)
- {
- int suma=0;
- for (int i=0;i<size;i++)
- {
- suma=suma+A[i];
- }
- return suma;
- }
- int compare (const void *a, const void *b)
- {
- if ((sumuj((int**)a,3)-sumuj((int**)b,3))>0)
- return 1;
- else if ((sumuj((int**)a,3)-sumuj((int**)b,3))==0)
- return 0;
- else
- return -1;
- }
- int main()
- {
- int array[][3]={{1,2,3},{7,8,9},{4,5,6}};
- printf("compare = %d\n\n",compare(array[1],array[2]));
- qsort((void*)array, 3,sizeof(int*),compare);
- printf("qsort = %d %d %d",array[0][0],array[1][0],array[2][0]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement