mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
11 lines
278 B
C
11 lines
278 B
C
int cmpval (const void *a, const void *b) {
|
|
return *(int *)a - *(int *)b;
|
|
}
|
|
int arrayPairSum(int* nums, int numsSize){
|
|
int sum = 0, i;
|
|
qsort(nums, numsSize, sizeof(int), cmpval);
|
|
for(i = 0; i < numsSize; i = i + 2)
|
|
sum = sum + nums[i];
|
|
return sum;
|
|
}
|