C ++ code to implement the above approach
import java . util . Arrays ; public class SumOfPairs { public void pairedElements ( int arr [ ] , int sum ) { int low = 0 ; int high = arr . length - 1 ; while ( low < high ) { if ( arr [ low ] + arr [ high ] == sum ) { System . out . println ( " The ▁ pair ▁ is ▁ : ▁ ( " + arr [ low ] + " , ▁ " + arr [ high ] + " ) " ) ; } if ( arr [ low ] + arr [ high ] > sum ) { high -- ; } else { low ++ ; } } }