Posts

[5 Aug 2020]Two elements whose sum is closest to zero

  Question:  An Array of integers is given, both +ve and -ve. You need to find the two elements such that their sum is closest to zero. For the below array, program should print -80 and 85. # include <bits/stdc++.h> # include <stdlib.h> /* for abs() */ # include <math.h>     using namespace std; void minAbsSumPair( int arr[], int arr_size) {      int inv_count = 0;      int l, r, min_sum, sum, min_l, min_r;              /* Array should have at least         two elements*/      if (arr_size < 2)      {          cout << "Invalid Input" ;          return ;      }              /* Initialization of values */    ...