You have $n$ integers and you want to pair them into $n/2$ pairs. You first sort the numbers, then pair the largest number with the smallest number, then the second largest number with the second smallest number, and so on. Repeat this process then you will get $n/2$ pairs of numbers, then you compute the sums of every pair.
If the flag INC is defined then you want to print these sums in increasing order. If two sums are the same then the sum with the smallest index in the original input array is printed first. Within a line you should print the smaller index first.
If the flag DEC is defined then you print these sums in decreasing order. If two sums are the same then the sum with the largest index in the original input array is printed first. Within a line you should print the larger index first.
void pairPrint(int numbers[], int n);
For example, if numbers are ${1, 3, 5, 2}$. The output should be as follows if DEC is specified.
For example, if numbers are ${1, 3, 4, 2}$. The output should be as follows if INC is specified. Note that since both ${1, 4}$ and ${2, 3}$ have sum 5, the pair ${1, 4}$ is printed first because the index of 1 (i.e., 0) is smaller than the index of 3 (i.e., 2).
Problem Description
You have $n$ integers and you want to pair them into $n/2$ pairs. You first sort the numbers, then pair the largest number with the smallest number, then the second largest number with the second smallest number, and so on. Repeat this process then you will get $n/2$ pairs of numbers, then you compute the sums of every pair.
INC
is defined then you want to print these sums in increasing order. If two sums are the same then the sum with the smallest index in the original input array is printed first. Within a line you should print the smaller index first.DEC
is defined then you print these sums in decreasing order. If two sums are the same then the sum with the largest index in the original input array is printed first. Within a line you should print the larger index first.For example, if numbers are ${1, 3, 5, 2}$. The output should be as follows if
DEC
is specified.For example, if numbers are ${1, 3, 4, 2}$. The output should be as follows if
INC
is specified. Note that since both ${1, 4}$ and ${2, 3}$ have sum 5, the pair ${1, 4}$ is printed first because the index of 1 (i.e., 0) is smaller than the index of 3 (i.e., 2).Subtasks
INC
is specified.INC
is specified..INC
is specified.INC
is specified.qsort
. EitherINC
orDEC
is specified.main.c
pair.h
pair.c
Sample Input
Sample Output (if a
#define INC
is defined)Sample Output (if a
#define DEC
is defined)