C ++ code to implement the above approach
#include <bits/stdc++.h> NEW_LINE using namespace std ; void pairedElements ( int arr [ ] , int sum , int n ) { int low = 0 ; int high = n - 1 ; while ( low < high ) { if ( arr [ low ] + arr [ high ] == sum ) { cout << " The ▁ pair ▁ is ▁ : ▁ ( " << arr [ low ] << " , ▁ " << arr [ high ] << " ) " << endl ; } if ( arr [ low ] + arr [ high ] > sum ) { high -- ; } else { low ++ ; } } }