#include using namespace std; // This assignment is worth 5 points // -1 for using math library // -1 for not having excess input checks or automatic 0 fills const int size = 10; int arr[size], k = 0, min_difference, difference_test; int index0 = 0, index1 = 1; char ch; string temp; int main() { cout << "Enter " << size << " numbers: "; do { cin >> arr[k]; k++; ch = cin.get(); } while(ch != '\n' && k < size); if(ch != '\n' && k == size) getline(cin, temp); else if(ch == '\n' && k < size) for(k; k < size; k++) arr[k] = 0; min_difference = arr[0] - arr[1]; // Initialize the difference if(min_difference < 0) min_difference *= -1; for(int i = 0; i < size - 1; i++) { for(int j = i+1; j < size; j++) { difference_test = arr[i] - arr[j]; if(difference_test < 0) // Absolute value application difference_test *= -1; if(difference_test < min_difference) { min_difference = difference_test; index0 = i; // Save the pair with the min index1 = j; } } } cout << "The closest numbers are " << arr[index0] << " at position " << index0 << " and " << arr[index1] << " at position " << index1 << endl; return 0; }