Pairs of Positive Negative values in an array | Print pair with negative and positive value ; For each element of array . ; Try to find the negative value of arr [ i ] from i + 1 to n ; If absolute values are equal print pair . ; If size of vector is 0 , therefore there is no element with positive negative value , print "0" ; Sort the vector ; Print the pair with negative positive value . ; Driven Program
function printPairs ( arr , n ) { let v = [ ] ; for ( let i = 0 ; i < n ; i ++ ) for ( let j = i + 1 ; j < n ; j ++ ) if ( Math . abs ( arr [ i ] ) == Math . abs ( arr [ j ] ) ) v . push ( Math . abs ( arr [ i ] ) ) ; if ( v . length == 0 ) return ; v . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < v . length ; i ++ ) document . write ( - v [ i ] + " " + v [ i ] ) ; } let arr = [ 4 , 8 , 9 , - 4 , 1 , - 1 , - 8 , - 9 ] ; let n = arr . length ; printPairs ( arr , n ) ;