Pairs of Positive Negative values in an array | C # program to find pairs of positive and negative values present 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 . ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static void printPairs ( int [ ] arr , int n ) { List < int > v = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( Math . Abs ( arr [ i ] ) == Math . Abs ( arr [ j ] ) ) v . Add ( Math . Abs ( arr [ i ] ) ) ; if ( v . Count == 0 ) return ; v . Sort ( ) ; for ( int i = 0 ; i < v . Count ; i ++ ) Console . Write ( - v [ i ] + " ▁ " + v [ i ] ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 8 , 9 , - 4 , 1 , - 1 , - 8 , - 9 } ; int n = arr . Length ; printPairs ( arr , n ) ; } }