#include void removeElements(int* array, int x, int y, int n) { int temp; /* Move the first element to the end of the array */ temp = array[x]; array[x] = array[n-1]; array[n-1] = temp; printf("Removed %d\n", array[n-1]); /* Move the second element to the 2nd last element of the array */ temp = array[y]; array[y] = array[n-2]; array[n-2] = temp; printf("Removed %d\n", array[n-2]); } void calcMinPair(int* array, int n) { int i = 0, j = 0; int x, y, val = 0; int min = 100; x = 0; y = 0; while (i < n) { j = 0; while (j < n) { if (i != j) { val = array[i] - array[j]; if (val < 0) val = 0 - val; if (val < min) { min = val; x = i; y = j; } } j++; } i++; } removeElements(array, x, y, n); } int main(int argc, char *argv[]) { int array[10] = {2, 3, 10, 5, 8, 9, 7, 3, 5, 2}; int counter = 10, i; while (counter > 0) { i = 0; while (i < counter) printf("%d ", array[i++]); printf("\n"); calcMinPair(array, counter); counter = counter - 2; } return 0; }