Identify pair of elements within an array having sum that is closest to zero when compared to any other pair in the array
Single File Programming Question
Problem Statement
Imagine you have an array of integer values, and you're tasked with identifying a pair of elements within the array. This pair of elements should have a sum that is the closest to zero when compared to any other pair in the array.
Your goal is to create a program that solves this problem efficiently. The program should accept an array of integers and return the pair of elements whose sum is closest to zero.
Input:
format :The first line of the input is an integer N representing the size of the array.
The second line of the input contains N space-separated integer values.
Output:
format :The output is displayed in the following format:
"Pair with the sum closest to zero: {value} and {value}"
Refer to the sample output for formatting specifications.
Code constraints : The given testcases fall under the following constraints:
1 ≤ N ≤ 100
-1000 ≤ array elements ≤ 1000
elements displayed based on the input order.
Sample test cases :
Input 1:
5
9 10 -3 -5 -2
Output 1 :
Pair with the sum closest to zero: 9 and -5
Input 2 :
4
2 -7 1 6
Output 2 :
Pair with the sum closest to zero: -7 and 6