Search if a pair can be formed with arr [ i ] .
int rem = sum - arr [ i ] ; if ( m . ContainsKey ( rem ) ) { int count = m [ rem ] ; for ( int j = 0 ; j < count ; j ++ ) { Console . Write ( " ( " + rem + " , ▁ " + arr [ i ] + " ) " + " STRNEWLINE " ) ; } } if ( m . ContainsKey ( arr [ i ] ) ) { m [ arr [ i ] ] ++ ; } else { m [ arr [ i ] ] = 1 ; } } }